Forums

Leverage Browser Caching

How do I enable and setup Leverage Browser Caching in pythonanywhere? It seems that the most popular solution is to edit the HTCACCESS file which is not used here.

Thanks,

By default, static files mappings add a Last-Modified header and honour the If-Modified-Since request header, so they are a good compromise for most use-cases. If you need more control, you'll need to server the files yourself and set the headers that you want.

Can you elaborate on your answer? I am not sure what you mean... My static html files are served from PythonAnywhere and my JS and CSS is served from Amazon S3. Where do I exactly add the leverage browser support? In my html files?

Thanks!!

Which files do you want to cache, particularly? If it's the JS and CSS stuff, then there's probably a setting somewhere in S3 -- we don't use it to serve stuff ourselves, so unfortunately I don't know where the settings might be.

If you're serving static HTML files from PythonAnywhere using the "static files" table on the "Web" tab, then all of the cache-handling stuff should work fine -- the static files system sends back appropriate headers to say when they should be cached and when they should not.

If you're serving dynamic HTML files from PythonAnywhere, then you can set various headers (read up on the ones Glenn mentioned above) in your responses to control caching, though the exact nature of when to cache and when to not cache depends very much on your website.