silverorange labs

Comments

sasha -

This seems much easier:

- compress file
(decent IDE will have an option to run this automatically every time after file.js is saved)

<pre>
gzip -c file.js >file.gz.js
</pre>

- serve file (.htaccess)

<pre>
#serve gzip JS when you can
<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>
</pre>

[edit: fixed brackets, sorry about that]

sasha -

Lets try this again. Posting thingy ate my brackets, so here is it with squate brackets rather then < and >

#serve gzip JS when you can
[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]

Mike Gauthier -

sasha:

Using gzip compression is an important part of reducing request size. We recommend using something like Apache + mod_gzip to automatically compress all requests for supported browsers.

May I refer you to a statement in the above post (emphasis added):

<blockquote>In tests on the Swat JavaScript code base, ShrinkSafe produced files that were 36 percent smaller after gzip compression.</blockquote>

mitch -

interesting.

also, i dont think your captcha is effectivly blocking spam...

Charles -

Mitch: That is true, which is why we hope the new reCAPTHCA works.

Mitch -

I do hope so too, and its a good use of the captcha principal (to digitize books)

blogging developer -

Another free online tool for compressing javascript is http://www.compressjavascript.com

cheers,
blogging developer
http://www.bloggingdeveloper.com

Felix -

Does anyone have any experience with Performance Testing an online site with new code that is now compressed JS? Should I be expecting Performance that is alot better than before?

Are there any other ways I can improve Performance without buying new hardware?

Thanks Felix

Mike Gauthier -

Felix,

Performance of compressed JavaScript should be roughly equivalent. The file size is not the most difficult part of the JavaScript interpreter's job.

You will, however, notice improvements in download speed which translates into page load times.

Johann -

I used ShrinkSafe before, but then switched to YUI (easier to use and also works with CSS) + gzip.

The latest thing I'm using on my QR Code Generator is to asynchronously load the JavaScript with a small (243 B) loader at the bottom of the page.

Makes performance absolutely awesome :-)

Post a Comment: Compressing JavaScript with ShrinkSafe

Email addresses are not displayed with your comment and will not be shared.
Allowed tags are: <em>, <strong>, <code> and <a href="url">. All other tags will be displayed as plain text.