4

I would like to compress the CSS and JS files on my server to minimise load times, problem.

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

Does anyone have another way to compress these types of files (and image files too if poss) without going the way of mod_gzip and mod_deflate.

Answers would be hugely welcome.

5
  • Do you have support for a programming language? Commented Dec 23, 2009 at 13:31
  • I'm not sure, how would I find out? Commented Dec 23, 2009 at 13:45
  • Ask your webhost? They probably have either ASP or PHP Commented Dec 23, 2009 at 13:53
  • @DanC: Ask your hosting provider. Commented Dec 23, 2009 at 13:53
  • sorry I thought (for some reason) you meant something else. The server does support PHP, the backbone to the site is Wordpress and written in PHP Commented Dec 23, 2009 at 13:57

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I have minified all the JS and CSS but would like to compress them too, just to maximise load speed.
@Dan: I'm sure you've already considered this, but why don't you change your host? It looks live your requirements have outgrown the typical "shared hosting" offer.
I unfortunately signed up for a long term package before really knowing anything about hosting, compression or anything really! The contract is up next year so exploring ideas to supplement the existing hosting before moving on as soon as possible!
@Dan: I understand your situation. However if compression is really important to you, I would bet that the time and mental energy you will use to work around this issue, will probably result more expensive than if you were to consider your remaining hosting commitment as a sunk cost (en.wikipedia.org/wiki/Sunk_cost). There are some really inexpensive offers out there which would give you total control on your web server, plus many other obvious benefits.
2

You can run your files through a script which would gzip them for you and add appropriate expiration headers. Either set up an 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 extended to also provide HTTP caching, and/or on-the-fly minification, further speeding up your visitors' browsing.

1 Comment

this sounds interesting, I will give it a try and report back if my coding fails me utterly - cheers!
2

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

This does introduce another step before you upload 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 file on the command line is as easy as, e.g.:

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

Make sure these files get served with the right content-type header though.

3 Comments

Although it's relatively uncommon today, what do you do when IE6 (whose support of gzip almost works) breaks on a gzipped file?
@Piskvor: Check the HTTP headers the browser sends. If Accept-Encoding: gzip, deflate is not present, send a non-gzipped version of the file.
“what do you do when IE6 breaks on a gzipped file?” I must admit, I don’t have enough experience to have encountered that.
1

Just as a sidenote: Compressing images would not be beneficial if these are already saved in a compressed format with the maximum compression that still looks good to the user.

6 Comments

probably a good point, cheers for pointing that out - I'm going a bit page speed mad here!
It would be nice if you could recompress the same file over again and again until it can be transmitted with a single bit though, wouldn't it? ;-)
it would be so awesome! 100/100 on yslow here we come!
Only problem is, all websites would look so similar... ;-)
Yes! And to make up for the similar content we could cram all website types into one. Enter Amazonoogletubewitterbook.com
|
0

Most programming languages support some data or file compression formats like ZLIB or GZIP. So you could use a programming language to compress your files with one of these formats.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.