1

I am looking at ways of speeding up my Magento site. One way that comes up is to Leverage Browser Caching and Expires Headers. I found to add this to htaccess-

<IfModule mod_expires.c>

# Enable expirations

ExpiresActive On

# Default directive

ExpiresDefault "access plus 1 month"

# My favicon

ExpiresByType image/x-icon "access plus 1 year?

# Images

ExpiresByType image/gif "access plus 1 month"

ExpiresByType image/png "access plus 1 month"

ExpiresByType image/jpg "access plus 1 month"

ExpiresByType image/jpeg "access plus 1 month"

# CSS

ExpiresByType text/css "access 1 month?

# Javascript

ExpiresByType application/javascript "access plus 1 year"

</IfModule>

My question is what about when I make changes? Most of my changes go to custom.css and I think I can set that individually. When I make a change to custom.css is there a way I can force people who have cached it to get the new one?

2

Yes. Enable css / js merging. This will add a hash to the generated files. When you clear js / css merge cache, new files are generated. New hash. Client gets new file.

Merging css or js can have unexpected results. If js or css filrs are not correct, and they merge with others, can cause issue. Point is. Test. Thouroughly. Don't just enable on live.

Hope that helps.

  • I came in after the site was already up and running. The previous developer said do not use Merge CSS/JS because it will break everything. I have had so much to work on I haven't messed with it yet but maybe I need to. Thank You – Tyler Jensen Jan 6 '17 at 16:11
  • I use merging ( and minification ) in all sites. Its not evil. Just sometimes need a litle love. – ProxiBlue Jan 6 '17 at 16:26
  • He said the same thing about compilation. I haven't gotten around to testing that but would you recommend that? – Tyler Jensen Jan 6 '17 at 16:54
  • I have never personally used compilation in any sites i manage. I tried to use it once or twice. Many years ago. Had issues. When i did get it working performance increase was marginal. Just not seened worth to me. – ProxiBlue Jan 7 '17 at 4:38
  • That said. Every site differs. You need to test and determine if it works for you. – ProxiBlue Jan 7 '17 at 4:40
0

One way to ensure visitors get the most up-to-date version of your CSS after you make a change would be to add a "query parameter" to the URI. Then, any time you make a change, you change the query parameter to "bust" the cache.

I use this module which dynamically adds a query parameter to your CSS (and JS) and automatically updates it when a change is made:

https://www.bubbleshop.net/magento-static-files-versioning.html

Here is some more info about using query parameters to "bust cache", in general:

https://css-tricks.com/strategies-for-cache-busting-css/#article-header-id-1

  • I update my css through ftp. Does that extension recognize that? If so that might be the way to go. Thanks for the help. – Tyler Jensen Jan 6 '17 at 16:14
  • Yes, the extension just looks at the "last updated" metadata on the file. The extension also has the option to manually update the query parameter which you could do any time you make a change. @ProxiBlue is correct that using the merge css feature is another option, if you can work out any style issues it causes. – Tim Cieplowski Jan 6 '17 at 18:10
  • @TylerJensen Did this work for you? – Tim Cieplowski Jan 11 '17 at 20:00
  • I ended up using the merge function and it worked like a champ. – Tyler Jensen Jan 11 '17 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.