views:

304

answers:

2

I have been trying, unsuccessfully, to get a HTML page to load an external GZIP compressed javascript file from the local filesystem using a HTML file such as this:

<html>
<head>
<script src="test.js.gz" type="text/javascript"></script>
</head>
<body></body>
</html>

When I open this HTML file directly in a browser, the Javascript file is not decompressed, but just included as-is. Since there is no webserver to tell the browser that the data is compressed, I was wondering if anyone knew of any other way of getting a setup such as this working? (the final result will not be running of a webserver).

+3  A: 

GZIP (de)compression of files is part of the HTTP/1.1 protocol which isn't used by browsers for loading local files. So I think the short answer is no. Sorry!

You could resort to uncompressed files, or decompress them before loading the web page, or running an HTTP daemon (web server) on the local machine which serves files to the web browser.

Hope that helps

Al
+1  A: 

No, there isn't.

I assume you are doing this for testing — in which case, don't worry. A properly configured web server will gzip files on the fly (and cache them). You don't need to link to a .js.gz version.

David Dorward