Optimizing the delivery of Javascripts on Joomla

Optimizing the delivery of Javascripts on Joomla

We have been working really hard with EasyBlog 5 and while we were optimizing the Javascript portion of EasyBlog 5, we have just realized that Joomla is not able to add gzip compression on most of the scripts which are included in our extension. This results into the file having to be larger than usual.

Since most of these Javascript files are served through it's own absolute URL, the only way to ensure that these files are served with gzip compression is by adding the block of codes below in your .htaccess file or Nginx configuration file:

 

Apache (.htaccess)

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript

 

Nginx

gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

By adding the codes above, we have noticed a great and drastic reduction on your script sizes! Not only does it solve issues with our scripts, any other Javascripts which are served from your Joomla site will automatically gets served with gzip compression as well! On a live site, which I have just tested, adding the codes above reduced a Javascript file from 1.1mb to 260kb. That's almost 450% reductions in size!

NOTE: The codes above would work on any of our extensions and as a matter of fact, it works for any Javascripts being rendered on your site.

Have fun trying this out! I have to get back to the codes right now :)

 

Comments (23)

Awesome! Thanks Mark.

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Justin

No problem Justin! I am greatly impressed at how much savings is added when you use gzip to compress the output.

  Attachments
Your account does not have privileges to view attachments in the comment
 

Thanks Mark, in the htacess i find :
AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the future.

what that mean ? still helpfull to add this line of code in the htaccess file ?

  Attachments
Your account does not have privileges to view attachments in the comment
 

What version of Apache are you currently on right now?

  Attachments
Your account does not have privileges to view attachments in the comment
 

i think apache2 !

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    HMED

Perhaps you should post your site's details on our forums and I would help you to check on this?

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Mark

ok thanks you ;)

  Attachments
Your account does not have privileges to view attachments in the comment
 

I don't see any change on my website after adding this in .htaccess!!

am i missing something? I tried testing with http://tools.pingdom.com

  Attachments
Your account does not have privileges to view attachments in the comment
 

Perhaps you already have such codes previously and that is probably why you are not noticing the differences?

  Attachments
Your account does not have privileges to view attachments in the comment
 

Hi

maybe you can step in to Joomla core dev and give them a hand to optimize Joomla core too? :)

That would be good for everyone...:)

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Joomla dev

This really has nothing to do with Joomla altogether :p It's just the way the webserver serves the content of the site. Joomla cannot include such codes in their .htaccess because if the webserver doesn't support gzip, it'll fail altogether :(

  Attachments
Your account does not have privileges to view attachments in the comment
 

I have simply used the template optimisation option by gavick with exceptions to work with JFC Connect among others. Nothing fancy.

I guess gavick optimisation already does it then. Thanks.

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Ningning Niumai

I am not really sure what Gavick Optimizations do for the site but if you want, post a new thread on the forums and I can have a quick inspect on the site for you :)

  Attachments
Your account does not have privileges to view attachments in the comment
 

Thanks for the info!

  Attachments
Your account does not have privileges to view attachments in the comment
 

No problem Chris :) Glad it helped!

  Attachments
Your account does not have privileges to view attachments in the comment
 

Thanks for taking a break to share this with us ;)

I found a site that provides a "gzip compression test"; I can't tell if it's legit but here it is if anyone wants to see.

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Eileen O'Donnell

Thanks for the link! Useful

  Attachments
Your account does not have privileges to view attachments in the comment
 
  1.    Eileen O'Donnell

Thanks for sharing this Eileen :)

  Attachments
Your account does not have privileges to view attachments in the comment
 

Just in case anyone is running Akeeba Admin Tools, by turning on "Automatically compress static resources" in the .htaccess maker, the same effect is acheived!

  Attachments
Your account does not have privileges to view attachments in the comment
 

Thanks for sharing this Dave :) Didn't know that Admin tools does this as well!

  Attachments
Your account does not have privileges to view attachments in the comment
 

I am glad to find this thread here. I have submitted the code to my host. I have quite a few sites with them and most of them are performing pretty well. But, if this would make them perform even better than I am happy.

Currently I do have one with that uses EasySocial, EasyDiscuss and EasyBlog which has been growing very SLOW. One of the reasons is that I have not been able to get the site to be fast. The pages take six seconds or longer. So, I hope that adding this code might help a...

I am glad to find this thread here. I have submitted the code to my host. I have quite a few sites with them and most of them are performing pretty well. But, if this would make them perform even better than I am happy.

Currently I do have one with that uses EasySocial, EasyDiscuss and EasyBlog which has been growing very SLOW. One of the reasons is that I have not been able to get the site to be fast. The pages take six seconds or longer. So, I hope that adding this code might help a LOT.

Also, I know I have change my homepage to not pull from the various modules of EasySocial, EasyDiscuss and EasyBlog. I was hoping to be able to show people some activity on the home page to entice them to sign up as members.

I previously used other compression tools like JCH-Optimize buth they were causing problems with my scripts and templates. I have the following pages that are all very slow still. (I just turned OFF all caching and the only compression is on my template. Here are the components of my site:

Home Page that pulls dynamic content from multiple components:
https://www.starch-smart.com/
I probably just need to not pull from so many sources?

EasySocial:
https://www.starch-smart.com/social

EasyDiscuss:
https://www.starch-smart.com/forum

EasyBlog:
https://www.starch-smart.com/blog

PS. These pages all are being reported as very slow in GTmetrix, Pingdom Tools and others...

Read More
  Attachments
Your account does not have privileges to view attachments in the comment
  Comment was last edited about 2 years ago by Sean Carney

I just added this bit of code to my site and it really seems to have made a difference in overall site page load times! Thanks for the tip!

  Attachments
Your account does not have privileges to view attachments in the comment
 

You are most welcome Gary :)

  Attachments
Your account does not have privileges to view attachments in the comment
 
There are no comments posted here yet

Subscribe To Our Blog

Subscribe to our blog by entering your email address:

Thanks! You have subscribed to our newsletter.

Joomla World Conference 2017

Tuesday, 03 October 2017 by Sylvie

We have acquired PayPlans from ReadyBytes

Wednesday, 06 September 2017 by Mark

EasySocial 2.1 Alpha Released

Wednesday, 30 August 2017 by Mark

Introducing EasyArticles

Thursday, 25 May 2017 by Mark

Echo Template Released

Tuesday, 24 January 2017 by Sylvie

Recent Posts From StackIdeas