Page 1 of 1

Need help in defer JavaScript and keep alive

Posted: Tue Jan 15, 2019 1:57 am
by Jassher
I have open cart and my site is

I need to fix gtmetrix error of defer javascript and enable keep alive option and leverage browsing cache. .
Please some one help me in that . please somebody tell me where to do that and how to do that and which code to use . ... m/g7FkeTtz

Re: Need help in defer JavaScript and keep alive

Posted: Sat Jan 19, 2019 1:22 am
by cyclops12
Click on the recommendation links in gtmetrix, I.E "Enable Keep Alive", then click the "whats this mean" button.
Read through these and they will help you solve your problems

Re: Need help in defer JavaScript and keep alive

Posted: Sun Jan 20, 2019 10:34 pm
by victorj
Keep alive is a server setting done in apache conf file, so if on a vps or cloud where you control your server yourself you can change this, you can try to add this line to your htaccess file
<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
otherwise it has to be done by your hosting company.

defer javascript has to be done in your header.tpl file.
be very carefull, defer or async javascript can break functionality of your site.
defer or better async evry line if javascript one by one and test your entire site including total checkout before defer or async next line.

to defer or async just add defer or async in your javascript line just after <script

be carefull it can break your site, difference between defer and async, if defer breaks a function you can try to async if it works fine if it does not that line cant be defered.

Browser cache a set of rules added to your htaccess file so things are cached by a users browser.
there are tons of website with numerous exaples how to do that.
Wich lines to use depends on your theme, just add those rules until gt metrix tels you that all are applied.

although your best results will come from making your images the right size and optimizing them it will reduce your page load dramaticaly resulting in a much faster website and better user expirience.

Oh before i forget, before starting to tinker around with optimizing your site make sure you made a or even better 2 backups of your working site.
(it took me 6 month to collect all knowhow and get my site up to 96% and get it as fast as possible)