How to improve js loading by letting them be cached

  • Posts: 634
  • Thank you received: 16
5 years 6 months ago #298460

-- HikaShop version -- : 3.5.1
-- Joomla version -- : 3.8.x

-- HikaShop version -- : 3.5.1
-- HikaMarket version -- : 2.1.1
-- Joomla version -- : 3.8.x

We are on the process to make my site fast and optimized. We managed to fix and improve a lot of things and now we are stalled on something GTMetrix is complaining about:

Resources with a "?" in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:

/media/com_hikamarket/css/frontend_custom.css?v=173
/media/com_hikamarket/css/otree.css?v=173
/media/com_hikamarket/js/hikamarket.js?v=173
/media/com_hikamarket/js/otree.js?v=173
/media/com_hikashop/css/frontend_custom.css?t=1468838255
/media/com_hikashop/css/hikashop.css?v=301
/media/com_hikashop/js/hikashop.js?v=301


I don't know how to get rid of this ?v=173 and ?v=301 parameter that according to GTMetrix is not allowing to cache those files by the browser.

Of course there might be a powerful reason for those files to be non-cached, I guess is to ensure updates always work right.

But now we are in a stable release of our site and we need to speed it up, we understand that when updating HikaComponents we'll need to clean caches to ensure good working.

QUESTION 1:

How can we avoid this parametrization of the script call so the site runs on browser cached .js

QUESTION 2:

Is there some of this files that you would encourage to keep them uncacheable?



Thank you.

Please Log in or Create an account to join the conversation.

  • Posts: 81540
  • Thank you received: 13069
  • MODERATOR
5 years 6 months ago #298465

Hi,

We add that parameter so that just after an update, you and your customers don't get weird crashes of the interface because the javascript file is still cached by the browser while the view has been updated and the javascript and the view don't match anymore.

Note that browsers do cache resource files with parameters in the URL. So you won't gain anything in speed if you remove that parameter.
If you use a CDN like cloudflare, they might not cache the resources if there are parameters in the URL, as it is mentioned by GTMetrix. However, if you don't use a CDN for your website, then doing that change will help almost no one as not many people have proxy caching servers (maybe for some big companies).
All that would do is avoid people from the same company to request the resources of the page if someone else there already requested them no too long ago and only for the first page that they look at (since after the first page, their browser will cache the resource file). And that's only if the proxy cache server doesn't support caching with parameters in the URLs, which I suppose most do.
The benefit is so slim I would recommend not bothering as 99.9999% of the pages won't be impacted.

Now, if you really want to do it, you can remove the code:

?v='.HIKASHOP_RESSOURCE_VERSION
in the file administrator/components/com_hikashop/helpers/helper.php
Note however that you will loose the change after each update of HikaShop.
Alternatively, some optimization extension like JCHOptimize can prevent that as they combine the js/css files together in one cache file. You just have to clear their cache after each update of an extension/joomla/etc.

The following user(s) said Thank You: PeterChain

Please Log in or Create an account to join the conversation.

  • Posts: 634
  • Thank you received: 16
5 years 6 months ago #298478

Hi Nicolas,

I appreciate very much your extensive, generous and well explained arguments.

Therefore I will move to other areas for optimization.

Big thanks

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum