1
votes

I am trying to enable caching for static files such as .css and .js. I am running a WSGI server with Python.

I have tried setting the following headers for caching purposes:

headers.add_header('Cache-control', f'public, max-age={expires.strftime(RFC_1123_DATE)}')
headers.add_header('Expires', expires.strftime(RFC_1123_DATE))
headers.add_header('Last-Modified', generate_last_modified())

Headers recieved in the browser:

HTTP/1.0 200 OK
Date: Tue, 21 Apr 2020 08:06:17 GMT
Server: WSGIServer/0.2 CPython/3.6.9
Content-Encodings: 
Content-Type: text/css; charset=UTF-8
Cache-control: public, max-age=Tue, 28 Apr 2020 08:06:17 GMT
Expires: Tue, 28 Apr 2020 08:06:17 GMT
Content-Length: 23399
Last-Modified: Tue, 21 Apr 2020 08:06:1587452777S GMT
Accept-Ranges: bytes

When using Chrome this code works and the files are stored and retrieved from the cache as you would expect. Chrome is using the Expires header and is ignoring the Cache-Control header.

I checked my developer tools and Disable Cache is not enabled. I checked my settings in Firefox in about:config, caching seems to be enabled.

So what am I missing here? Am I missing a header, is an ETAG required, why is Expires working in Chrome but not in Firefox?

1

1 Answers

0
votes

I found the solution.

Firefox cache was full, so after emptying the cache it started sending the if-modified-since header again.

Also my server was returning the current time as the last-modified time instead of the actual last modified time.

To fix the issue all I had to do was compare the if-modified-since time from the browser with the last modified time from the file and send a 304 status if nothing changed.