Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I gzip my JavaScript and CSS files?

Tags:

I have a problem, I have to gzip a prototype Lib, but i totaly have no idea how to do this, where to start and how does it works. :)

I find some tutorials but that wasn't helpful...

So I have a folder with my JS Files:

/compressed/js/ 1.js 2.js 3.js

I'm calling these files for a test in this file

/compresses/index.php

<link rel="javascript" type="text/js" href="js/tabs.js" /> <link rel="javascript" type="text/js" href="js/fb.js" /> 

So what do I have to do? :)

like image 328
Fribu - Smart Solutions Avatar asked Apr 19 '10 08:04

Fribu - Smart Solutions


People also ask

How do I gzip CSS and Javascript files?

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. You need access to your vhost/server config to globally enable compression. You don't need to prepare your files, they're compressed automatically on request.

How do I combine CSS and js files?

To combine external CSS files, you can simply copy / paste all of your CSS code into one main file. Therefore all of the content from within the other CSS files will now reside within the main file allowing the browser to only make one request for a CSS file instead of multiple.

How do I compress components with gzip?

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!


1 Answers

You can use apache's mod_deflate to automatically compress your files on the fly.

Example:

AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript  

[edit]

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.

like image 141
elias Avatar answered Sep 23 '22 09:09

elias