Tag Archives: CSS

Transparently compressing JS and CSS files with PHP

When I develop a web site, I usually configure it to compress the content before sending it to the end user. Downloading resources such as HTML, CSS and JS files is then smaller and thus faster.

It is possible to configure this in the .htaccess file (in case the server runs Apache) as well as it is possible to program it in PHP.

Unfortunately, it looks like my web hosting company doesn’t allow the former, so I had to take the PHP way for compressing resources in geo:truc.

The PHP code for doing this is rather simple:

This works fine: write a PHP script, put the code above in it, and it’s done! It works with HTML files, and it’s possible to use it as well with JS ans CSS files, although they need to start with this snippet and have a .php extension.

But how to do when using different JavaScript libraries that are now commonly used? A new .php file for every new version of jQuery? It sounds fastidious. And how to make it transparent, i.e. not passing a URL like http://www.example.com/js/compress.php?file=jQuery.js ?

Continue reading

geo:truc: faster, harder, stronger, louder

A lot of work has been done lately to improve geo:truc.

There is at this point no new feature, no, the work has been to make it faster by reducing the size of the different components (HTML, javascript, CSS), by using compression and by using CSS-sprites.

The size of the text files was reduced by optimizing the code and by trying to write it in a more compact way (less new lines etc).

The flags on the top of the frontpage were already sprites, but I generalized this use. The point is that only one image file is downloaded once instead of a lot of small ones (one for the logo, one per icon etc). This avoids to make a lot of calls to the server with a an extra response time per request.

If anything is wrong in the layout, try a reload or to clean your cache.

Enjoy now a faster geo:truc!