Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

JavaScript compressor


Go to End


8 Posts   3258 Views

Avatar
Tim

Community Member, 201 Posts

27 April 2007 at 5:37pm

Edited: 27/04/2007 5:52pm

It would be nice if all the Javascript which was included on pages was be compressed.

This look like a cool way to do it

http://ajaxian.com/archives/jscsscomp-javascript-and-css-files-compressor

Avatar
Sigurd

Forum Moderator, 628 Posts

27 April 2007 at 10:43pm

Edited: 27/04/2007 10:50pm

There's a much easier way that isn't the CPU overhead of using PHP.

http://httpd.apache.org/docs/2.0/mod/mod_deflate.html

Every CSS, Javascript, HTML or plain text file in general, is already being compressed on this server.

We've used that technique for about 3-4 years now :)

You can tese this with:

http://www.silverstripe.com/ssopen/javascript/prototype.js

Original Size: 46 K
Gzipped Size: 10 K
Data Savings: 78.26%

Without having mod_deflate on, we wouldn't permit us to use such large JS files :)

http://www.whatsmyip.org/mod_gzip_test/?url=aHR0cDovL3d3dy5zaWx2ZXJzdHJpcGUuY29tL3Nzb3Blbi9qYXZhc2NyaXB0L3Byb3RvdHlwZS5qcw==

Avatar
Ingo

Forum Moderator, 801 Posts

28 April 2007 at 2:05am

but still, that's only on our silverstripe-servers - providing a precompressed prototype/scriptaculous that loads fast even without mod_gzip might be a good default option. another thought i was pondering for a while is having more granular css-includes for form-fields, which are automatically composed into one file on the serverside (to avoid the HTTP-overhead). currently we have all kinds of styling in cms_right.ss, which should actually go into sapphire/forms.

Avatar
Sam

Administrator, 690 Posts

28 April 2007 at 12:53pm

That's something that I've pondered too, Ingo. The issue is that if you have slightly different includes on each page of your site, you're going to need to have a separate CSS download for each page - which is even worse.

Ideally, you want to "chunk" the output into logical groupings of CSS content, however, such an algorithm would take some thought.

A simple way would be to give each CSS file a tag (such as form, cms, homepage, etc), and group CSS includes according to their tag. It's unclear, however, as to whether this would actually provide any benefit.

Avatar
qhoxie

Google Summer of Code Hacker, 39 Posts

8 May 2007 at 6:27pm

siggy,
the differences between compressed js via mod_gzip and a script packer have been show to be negligible, being as they use similar algorithms

as ingo mentioned though, that is up to the user if they install ss themselves
i agree that it would behoove ss to distribute compressed js files

that said, while the method that tim mentioned is a neat trick, i dont see a disadvantage to just distributing the compressed files as opposed to doing it on the fly

Avatar
Sigurd

Forum Moderator, 628 Posts

16 May 2007 at 10:05am

Yeah distributing precompressed files is a good idea :)

Avatar
Tim

Community Member, 201 Posts

3 June 2007 at 7:32pm

Avatar
msantang

Community Member, 41 Posts

7 June 2007 at 1:23am

Edited: 07/06/2007 11:29pm

Hi

This is interesting too.

adding this in .htaccess you can use modrewrite to automaticaly get the compresed js if your browser can handle it.

<FilesMatch “\\.js.gz$”>
ForceType text/javascript
Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch “\\.js$”>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !”.*Safari.*”
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*)\.js$ $1\.js.gz [L]
ForceType text/javascript
</FilesMatch>

See:
http://joseph.randomnetworks.com/archives/2006/07/13/compressed-javascript/

Right now im using this other solution:

http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files

Is a good one but i use it to precompress the frontend javascript only.
To precompress the cms js files i have to edit some silverstripe code.