Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Blobs do NOT get cached? How to turn on blob cache?

+4 votes
1,399 views
asked Nov 25, 2013 in Q2A Core by q2apro
edited Nov 25, 2013 by q2apro

I remember that gidgreen once said all blobs get cached by the browser, correct headers are sent. Looking to the Firefox Developer console, I see that this is not the case instead code "304" (yellow bubble) they get loaded completely anew, code "200".

screenshot

So, how to turn on the blob cache?

 

Note: All my blobs are loaded from the database.

And I am using htacess to define the cache time:

    ExpiresByType image/gif         "access plus 1 month"
    ExpiresByType image/jpg         "access plus 1 month"
    ExpiresByType image/jpeg         "access plus 1 month"
    ExpiresByType image/png         "access plus 1 month"
 

 

PS: You can see the same effect here in this forum.

commented Nov 25, 2013 by q2apro
Ah, now I found the post again: http://www.question2answer.org/qa/13816/images-generated-getting-cached-browser-missing-something

and Scott's answer: "It uses the max-age directive, which tells the browser to cache the image for 30 days. In this case no Last Modified value is needed."

But still with my browser, the images get downloaded from the server again. Maybe the max-age directive depends on the browser? I'd like to see the "headeres" cache implemented.

1 Answer

+1 vote
answered Nov 25, 2013 by maxjtechno
selected Nov 26, 2013 by q2apro
 
Best answer

If I'm not wrong q2a blobs are cached, and yours not smiley

If I open a question page (e.g. this one) from the question list (clicking on the link, here on q2a) the image the first time is downloaded from the server, the second time (same operation, go on the question list and click on the question link) is downloaded from the cache (do not do refresh of the question page or it will be always downloaded)

In your site I see it's always downloaded from server.

From a quick look the only difference in the response I can see is these "suspicious" header that your server sends back :

Cache-Control : private, no-cache, no-store, proxy-revalidate, no-transform

and

Pragma : no-cache

 

commented Nov 26, 2013 by q2apro
NOW it works, thank you so much! :)

The tip of *not refreshing* the site by F5 but just navigation through links showed me the caching, damn it! Why didn't I know before.

Furthermore I am not using the both directives from above anymore.

This is my caching now:

# CACHING
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css     "access plus 1 month"
   
    ExpiresByType text/javascript             "access plus 1 month"
    ExpiresByType application/javascript     "access plus 1 month"
    ExpiresByType application/x-javascript     "access plus 1 month"
   
    ExpiresByType application/json     "access plus 0 seconds"
    ExpiresByType application/xml     "access plus 0 seconds"
    ExpiresByType text/xml         "access plus 0 seconds"

    ExpiresByType application/x-shockwave-flash     "access plus 1 month"
   
    ExpiresByType image/ico         "access plus 1 month"
    ExpiresByType image/x-icon         "access plus 1 month"
    ExpiresByType image/gif         "access plus 1 month"
    ExpiresByType image/jpg         "access plus 1 month"
    ExpiresByType image/jpeg         "access plus 1 month"
    ExpiresByType image/png         "access plus 1 month"
   
    ExpiresByType video/mp4         "access plus 1 month"
    ExpiresByType video/ogg         "access plus 1 month"
    ExpiresByType video/webm         "access plus 1 month"
   
    ExpiresByType application/atom+xml        "access plus 1 hour"
    ExpiresByType application/rss+xml            "access plus 1 hour"

    ExpiresByType application/font-woff            "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject    "access plus 1 month"
    ExpiresByType application/x-font-ttf        "access plus 1 month"
    ExpiresByType font/opentype                "access plus 1 month"
    ExpiresByType image/svg+xml            "access plus 1 month"
</IfModule>

Thanks again :)
commented Nov 26, 2013 by q2apro
I reduced it now to:

# CACHING
<IfModule mod_expires.c>
    ExpiresActive On
   
    ExpiresByType text/css     "access plus 1 month"
    ExpiresByType text/javascript             "access plus 1 month"
    ExpiresByType application/javascript     "access plus 1 month"
    ExpiresByType application/x-javascript     "access plus 1 month"
   
    ExpiresByType image/ico         "access plus 1 month"
    ExpiresByType image/x-icon         "access plus 1 month"
    ExpiresByType image/gif         "access plus 1 month"
    ExpiresByType image/jpg         "access plus 1 month"
    ExpiresByType image/jpeg         "access plus 1 month"
    ExpiresByType image/png         "access plus 1 month"
   
    ExpiresByType application/x-shockwave-flash     "access plus 1 month"
   
    ExpiresByType video/mp4         "access plus 1 month"
    ExpiresByType video/ogg         "access plus 1 month"
    ExpiresByType video/webm         "access plus 1 month"
</IfModule>
...