CSS and JS compression without mod_gzip and mod_deflate

I would like to compress CSS and JS files on my server in order to minimize load time, problem.

My hosting is with Streamline.net (a big mistake, never going there) that will not activate mod_gzip and mod_deflate due to security issues.

Does anyone have any other way to compress these types of files (and image files, if possible) without going along the mod_gzip and mod_deflate paths.

Answers would be very welcome.

+4
source share
5 answers

You can run your files with a script that will gzip them for you and add the appropriate expiration headers. Either configure the URL rewrite, or rewrite the URLs manually:

<script src="js/somescript.js"></script> 

becomes

 <script src="compress.php?somescript.js"></script> 

and in compress.php you can do something like

 <?php $file = 'js/' . basename($_SERVER['QUERY_STRING']); if (file_exists($file)) { header ('Last-Modified: ' . date('r',filemtime($file)); header ('Content-Type: text/javascript'); // otherwise PHP sends text/html, which could confuse browsers ob_start('ob_gzhandler'); readfile($file); } else { header('HTTP/1.1 404 Not Found'); } 

Obviously, this can be expanded, as well as provide HTTP caching and / or on-the-fly viewing.

+2
source

Yes, the answer is Minification .

Obviously, it will not compress as much as gzip or deflate . But it helps, and it is very easy to do with the right tools.

+4
source

Instead of getting mod_gzip to gzip your CSS and JavaScript files dynamically, you can download them yourself and then download them.

This takes another step before loading CSS and JavaScript, but it works and maybe even saves a tiny bit of server processing time for each request compared to mod_gzip.

On Mac OS X, gzipping a command line file is as simple as, for example:

 gzip -c styles.css > styles-gzip.css 

Verify that these files are served by the correct content header.

+2
source

Just like a side effect: image compression is not beneficial if they are already saved in a compressed format with maximum compression, which still looks good to the user.

+1
source

Most programming languages ​​support some data or file compression formats, such as ZLIB or GZIP. Thus, you can use a programming language to compress your files using one of these formats.

0
source

All Articles