Browser caching: still have reports to add expiration times to some images

I have the Browser caching enabled for all MIME types Hummingbird, however, I am still have reports to add expiration times to some images. How can I solve this?

  • Kasia Swiderska

    Hello David,

    I have checked Hummingbird settings and the code in htaccess (I also removed and inserted it again) for browser caching and it all looks correctly.
    I have tested the same code on my site and it give correct results (all images have correct expiry set).
    In this case I will kindly ask you to contact your hosting provider to ask about this issue - if they have settings for browser cache on server that would override what is set in the .htaccess right now.
    Please let us know what will they say.

    kind regards,
    Kasia

  • Adam Czajczyk

    Hello David

    That's not much "encouraging" response from the host but on the other hand, I'm not quite sure if there is anything that actually has to be done.

    I mean: while support access doesn't seem to work anymore (it might have expired as it's time valid), I have checked your site with Google PageSpeed Insights. It does suggest enabling browser caching for some resources but none of them are images. It's only reporting some specific resources that are external and are related to google maps - but since they are external there's not much that could be done about them.

    Other than this, the PageSpeed score is quite good. There is a reference to the images but it's about optimizing them. To be exact, it's reporting the /uploads/2017/08/FC-logo3.jpg image (which, I presume, is a logo on site) as needing to be "compressed and resized".

    If you are already using our WP Smush Pro plugin it usually means that it doesn't even need to be compressed but rather resized. For example, in case of the aforementioned image, its dimensions - I mean image file - are bigger than how the image is displayed on the site so as a result it's dynamically scaled down by the browser. That's why PageSpeed is reporting it. Manually resizing that image to the size that's used on site would solve that report.

    That being said, if you are still getting those cache expiration time reports, would you please:

    - go to "WPMU DEV -> Support" page in your site's back-end to make sure that the support access is active? If it is, revoke it and re-grant, it should reactivate it for us

    - share a screenshot of such cache report?

    Best regards,
    Adam

  • Adam Czajczyk

    Hello David

    Thank you for re-enabling access. However, I think we had a small misunderstanding at the start - I think we both (me and Kasia) were referring to the wrong site. According to your last post the site is "http://www.kiwibedandsofas.co.nz" which wasn't noted in your initial post but you have assigned a different site of yours to this thread. Thus, we focused on the one assigned to the post.

    I apologize for confusion!

    That being said, I have checked the correct site now and I can see the expiration issue, PageSpeed reports it. I run some other tests on this and it looks that the server (web-server - Apache) is adding ETag header to these images. The "ETag" header is one of the methods of cache control but it breaks the "fixed caching".

    I'd start with trying to disable that feature. Usually that's possible via .htaccess so let's try it:

    1. access your server to edit .htaccess file of the site
    2. find the code added by Hummingbird, specifically this part:

    <IfModule mod_headers.c>
      <FilesMatch "\.(txt|xml|js)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(css)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    </IfModule>

    3. replace this block with this:

    <IfModule mod_headers.c>
    Header unset Etag
      <FilesMatch "\.(txt|xml|js)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(css)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    
      <FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>
    </IfModule>
    FileEtag None

    4. Save .htaccess.

    After that check if there are still reports on the browser cache expiration times on images. If yes, please get in touch with your host again and ask them if they are able to disable ETags for your domain on their end.

    Let me know about results, please.

    Best regards,
    Adam

  • Predrag Dubajic

    Hi David,

    It seems that rules are still showing as properly assigned but the report is still showing that browser caching is not enabled for images.
    Can you tell us if you tried asking your hosting provider to disable ETags as Adam mentioned above?

    Also, can you try disabling Browser Caching completely and then see if the report is showing that it's disabled for all files, not just images, and if that's the case than there's most likely something on your server side that's overwriting the rules we applied and preventing the images from being cached in browser.

    Best regards,
    Predrag

  • Adam Czajczyk

    Hello David

    Thanks for your response!

    It seems that the issue is still the same. Checking the site with external "testers" is still showing that either "expiration date is not specified" or that "ETag detected" (depending on what tool is used).

    That would mean that while they (the host) may indeed not impose any caching rules, there is something in the server configuration that's "forcing" those ETags for either all media files or at least .jpg images.

    Since you tried to disable ETags via .htaccess and that didn't work, I'm afraid "pushing" a bit more on the host might be the only way to go.

    However, there's something that I'd like you to try in addition (or rather first):

    1. Edit the .htaccess again and try replacing this block of code

    <FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
       Header set Cache-Control "max-age=691200"
      </FilesMatch>

    with this one

    <FilesMatch "\.(jpg|jpeg|png|gif|swf|webp)$">
       Header set Cache-Control "max-age=691200, public"
      </FilesMatch>

    Then save the file, clear caches on site, on server (if there is any server-side caching tool enable) and check the site again - you may run the same report and if it helped you should see that the "Leverage browser caching" section doesn't report these images any more.

    If that doesn't change anything, please also test one more thing: switch the site (temporarily) to a Twenty Seventeen theme and again - clear all caches and test it.

    If that doesn't help as well, then either "push" your webhost a bit more regarding those ETags (as this is a server side thing) or - the other option - would be to just ignore that particular issue, I'm afraid.

    Keep us updated, please.

    Kind regards,
    Adam

  • Kasia Swiderska

    Hello David,

    From what I see most images at the moment on your site (home page) are placed in elements that will be not present when switching theme - so image of credit cards is in sidebar of current theme, but when you will switch to theme 2017, sidebars will not be the same.
    Checking the reports it looks that only image of sleeping kitten was displaying after theme switch, hence the difference there when it comes to the amount of the images reported.
    But even with the one image, we can see the issue is still there - so we are back to last suggestion from Adam post https://premium.wpmudev.org/forums/topic/browser-caching-still-have-reports-to-add-expiration-times-to-some-images#post-1330711

    Would it be possible to show your hosting provider this whole thread so they will see what we tried?

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.