Web Analytics Made Easy -
StatCounter Preventing Image Caching Via .htacces - CodingForum

Announcement

Collapse
No announcement yet.

Preventing Image Caching Via .htacces

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Preventing Image Caching Via .htacces

    I was running the google console page speed insights and i found i needed to stop my images from caching.

    So i read this article over on stack

    stackoverflow.com/Questions/728616/disable-cache-for-some-images

    here is my .htaccess file

    Code:
    #The absolute best way I've found to solve
    #this is to use ETAGS inside a .htaccess file
    #in your images directory. The following tells
    #Apache to send a unique hash to the browser in
    #the image file headers. This hash only ever
    #changes when time the image file is modified
    #and this change triggers the browser to reload
    #the image the next time it is requested.
    #source https://stackoverflow.com/Questions/728616/disable-cache-for-some-images
    
    <FilesMatch "\.(jpg|jpeg|png|ico)$">
    FileETag MTime Size
    </FilesMatch>
    My question is, is this actually the best way. I used to just put a random value at the end of the url but this article says that is not the best way....

    So what is the best way?

    Thanks
    If a php file only has php code within it you do not need to use the closing php tag
    A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
    durangod is short for durango dave

  • #2
    The what now? Are they really being updated that frequently that a cache HIT is a bad thing?!?

    I would suspect that like a LOT of things Pagespeed Insights says, it's talking out its backside. See the idiotic halfwitted BS about moving style into the markup if it effects things above the fold. If you have complex enough a HTML, CSS, and Scripting for that to pay any benefit, you've got too damned much code.

    I mean if it's a different file with different content, change the filename. Otherwise what's wrong with having images cached? It's kind-of the point.
    I'll kill you and your dreams tonight, begin new life.
    Bleed your death upon me, let your bloodline feed my youth.
    https://cutcodedown.com

    Comment


    • #3
      Yeah i guess google got me again, i took my results too seriously when its not necessary. And you are correct, that is the point.
      If a php file only has php code within it you do not need to use the closing php tag
      A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
      durangod is short for durango dave

      Comment


      • #4
        You know, I wonder if Google is saying that because three or four years ago they broke CTRL-F5 actually flush js, css, or images for new copies despite that being the point of it over a normal F5... and still haven't fixed it.

        Would be very Google. "We broke the browser engine, but now everyone out there needs to change their sites to fix it."
        I'll kill you and your dreams tonight, begin new life.
        Bleed your death upon me, let your bloodline feed my youth.
        https://cutcodedown.com

        Comment


        • #5
          Now in developerment if one is moving stuff around often and working on files i can totally see the need for no cache. There is nothing more frustrating than thinking your page is perfect when its garbage because your not getting the most current version. Or changing something that does not need to be changed for the same reason. But after that, the images will stay where they are and everything is pretty much set and so caching is the way to go.
          If a php file only has php code within it you do not need to use the closing php tag
          A good way to remember objects from arrays is you shoot objects with arrows Example: $name->id; then Arrays are $name['id'];
          durangod is short for durango dave

          Comment

          Working...
          X