Question

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).

Was it helpful?

Solution

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

OTHER TIPS

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.

As AI pointed out, gzip decompress feature is not there for web browsers. You may, however, configure web servers to compress the static files for transfer. The web browsers will decompress the files transparently and serve the save-bandwidth purpose.

Here is a reference for how you do so in Apache: http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/ If you are on other web servers, you can Google it up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top