Support Forum

JS and CSS Compaction and Compression

YS Yellow Swordfish
Yellow Swordfish
Member

I spent time yesterday investigating script compaction and compression and have to say that after much experimentation and whilst knowing that the file sizes do get reduced, I remain not totally convinced of the worth.

It is worth considering the downside, which is that every time we, as developers, make a CSS or JS change then those files need to be re-compressed although, to be fair, this can be a part of the release regime. It is also important to remember that we will need – at least as far as CSS files go – to still supply the uncompressed files so users can make modifications – something we will always be unable to stop.

CSS files can really only be compacted – not compressed. Using 'sf-admin.css' as a trial the base file weighs in at 20,330 bytes. The best compaction I got bought it down to was 15,434 bytes. Hardly earth shattering. The 'smoke' skin (just for a test run) with comments removed gave me – 49,646 to 36,156. 

JS files can be compacted – or 'packed' – and the compacted file can then also optionally be compressed. 'sfa-admin.js' starts out at 15,818 bytes. When packed it goes down to 7,300. Adding the second compression stage bought it down to 5,841 bytes. This is a good saving but it must be remembered that the server then has to de-compress before it delivers it. This may be fast (the decompression code is built into the final file) but for the added saving and more complex creation I would suggest hardly worth it.

I woud suggest that full compression is probably worth while on very big scripts but none of ours really are that big and compaction, without the decompression overhead, would be the best course if we decide to do this. I would add that I tried full compression on ALL of our scripts and only had immediate problems with one of them although clearly full script testing will be required.

If we decide to compact both CSS and JS files (and I am not necessarily including skin CSS here) then i think we would need to supply both the source file and the packed file. It woud be possible – we need to discuss whether it is desirable – to allow the end user to decide which to run with.

Comments and ideas welcome of course. But i think we need to decide quickly on all points as getting final scripts onto our site for some testing time before public release is needed.

I will apologise now for spelling errors and typos above. I am writing this outside in sunlight and I can't see the spell checker underline in the glare!

2 Answers

New Answer

MP Mr Papa
Mr Papa
Member

I am used to the typos and hardly notice anymore! Surprised

I am happy to leave stuff uncompressed…  I have never really understood the savings on such small files…  I think we have to leave the skins uncompressed for sure and providing both would be confusing for most…

YS Yellow Swordfish
Yellow Swordfish
Member

Happy to leave them uncompressed. However what i think WOULD be worth it would be to pack all of the JS files that are not ours – some of the jQuery plugins etc. In oither words JS files that we do not change.

As an aside – and in contradiction to makeing files smaller – we do badly need to document our JS functions! Not necessarily every arhument but just a note as to what they all do…