Forums

Browser expires cache of static files like Images, css, js etc.

Can you guys point to me a configuration file where i can feed in browser expires cache?

or let me know, who do i achieve this?

Unfortunately we don't have that. I'll add a ticket with an upvote on your behalf.

Hi Giles,

I see the ticket is open for about an year now. Do you have a ETA on the same? This is a primary need for any webapp. This feature enables us to improve the site speed drastically.

Help Appreciated Thank you very much!

Unfortunately we don't have an ETA.

What kind of configuration would you need? For example, a per-file or a per-directory way of setting the expiration date, or something like that?

Hi Giles, yes set an expiration date to all the static files, to start with.

Thanks

Giles, Is there a way I can set expiration for each files in the static ? Thank you for your help

Unfortunately no, there isn't. It's certainly something we can look into (I've added an item to our to-do list) but I can't give you any promises or an ETA.

I would be thankful if you could push this up your pipeline. The site we are running has poor site speed score from google due to the above issue. This feature will bring the score up drastically.

That's odd; our static file serving should be super-fast, even without caching. Do you have a link to the score that you could share? If you'd prefer to share it privately, just use the "Send feedback" link above.

Hi Giles,

screenshot of the pagespeed score and google recommendation

Let me know your thoughts

Thanks

There's nothing we can do about that immediately, but we'll look at implementing cache parameters for everyone.

Hi there -- sorry, when I asked for the screenshot, I was more interested in the stuff that's not to do with browser caching; it's possible that there are things mentioned there that we might be able to address faster than cache expiry headers.

Giles, This is the biggest piece that slows the site down. I have optimized many other things to bring up the score from 9 to 35.

PA - This is the 1st time I'm disappointed with you guys. PA does not allow 1. Partial Content - Status 206 with byte ranges to support media streaming 2. Browser Caching

LMK, if you guys can think of an alternative to help me out here.

Thanks Much Appreciated

Pk

It just seems really weird to me that you'd get a score of 35/100 just because of the lack of caching on the static assets. I just ran the "PageSpeed Insights" tool on another site that's hosted on PythonAnywhere, and it got 92/100. web2py.com, also hosted with us, gets 71/100.

I think you could probably improve the score drastically by optimising some of those images. The front page of your site is 3.4MB in size, and Google seems to be saying that it really doesn't need to be.

This isn't to say that we don't need to support browser caching, of course -- we do. But I think that even if we did, your page score would be pretty low because of the size of the images.

Just subscribed to this topic. Waiting patiently

Which feature are you most keen on? The partial content stuff? Or browser caching? If it's the latter, it's worth noting that we do have a certain level of caching enabled:

  • When a browser requests a static file, we send back a "last modified" field with it (based on the file's timestamp), and the browser will store that in its own cache.
  • When the browser requests the same URL again, it will send along a header saying "don't give me all of the content if it's not been changed since time X", where X is the value it got in the "last modified" header the last time it receives it.
  • When we receive a request that has that header, we check it against the file's current timestamp.
    • If it hasn't been modified, we send back a "304 not modified" response, which just contains a header -- no content. The browser can then use its cached copy
    • If it has been modified, we send the new contents back with a new "last modified" field.

This means that while there will be incoming requests for cached files, the content won't be sent unnecessarily, so they will load much faster.