Moo.tools is neat, I love it and use it whenever I can, but one thing is still bugging me: its size.
Even though moo.tools can be downloaded compressed (using the great php5 version of dean edward’s packer), I personally find 18kb of javascript too much.
So I started researching a bit with Google and found out different way of compressing moo.tools (or actually whatever javascript you have) even further:
The first method, which I am using works like this:
+ You rename your javascript file (moo.tools) from the original filename.js to filename.js.php
+ Open the file with your favourite editor and add the following line just at the very TOP of the code:
+ Next, scroll down to the end of the file in your editor and add the following to the bottom:
+ Save your file and upload it.
Now add it to your website using the old HTML code, but keep in mind to add the .php-file extension.
It might look like this:
I was able to reduce the whooping 18kb moo.tools down to 9kb this way. Well, actually I did not do anything, but the server and its php and zlib.
Other methods:
At the top of Javascript:
.htaccess method
Save a compressed javascript file as *.jgz, and write .htaccess like this.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ".*Safari.*" [OR]
RewriteCond %{HTTP:Accept-Encoding} !gzip
RewriteRule (.*)\.jgz$ $1\.js [L]
AddType "text/javascript;charset=UTF-8" .jgz
AddEncoding gzip .jgz
Filesmatch .htaccess method:
ForceType text/javascript
Header set Content-Encoding: gzip
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
Sources / Ideas:
1. paulstamatiou.com
2. randomnetworks.com
Read More