Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Gzip a javascript file?

179KB of jQuery is Minified and Gzipped to 26KB. I am trying to do the same compressions to my javascript files and found the Yuicompressor to Minify it. But I am still searching for a way to Gzip it.

How can I Gzip my Javascript files?

like image 576
siva636 Avatar asked Dec 04 '10 06:12

siva636


People also ask

How do I gzip CSS and JavaScript files?

Show activity on this post. To check if your apache server has already output compression enabled, put the example above into an . htaccess file. Then load an html or js file via the server and check the headers for "Content-Encoding", if it says gzip or deflate, it is enabled.

How do I gzip a file from a website?

Gzip on Windows Servers (IIS Manager)Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!


2 Answers

If you are using it in a webpage, gzip is a configuration method in your web server. The file is gzipped by the server, sent to the browser. No manual action is needed. For Apache: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html.

If you are delivering the code to developers, you could use the gzip command.

like image 103
Ryan Li Avatar answered Oct 06 '22 01:10

Ryan Li


You would use gzip, the GNU compression utility. Luckily, the gzip algorithm and file structure is implemented by numerous other tools, such as 7zip (for Windows). You can configure your server (via mod_deflate or others) to compress files on the fly, but for static content its a waste of CPU power.

Here is an article which shows how to transparently serve pre-compressed gzip to browsers which support it: http://blog.alien109.com/2009/03/17/gzip-your-javascript/

like image 26
Yann Ramin Avatar answered Oct 06 '22 00:10

Yann Ramin