Is it possible to load gzip compressed javascript without a webserver?

26,791

Solution 1

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

Solution 2

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.

Solution 3

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.

Share:
26,791

Related videos on Youtube

Admin
Author by

Admin

Updated on July 23, 2020

Comments

  • Admin
    Admin almost 4 years

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

  • con-f-use
    con-f-use over 7 years
    Any browser-plugin, that can deal with this. It would be handy to test gzipped files locally without a webserver installed...