Question

I'm running Google Page Speed on my website which is in Python/Bottle on Google App Engine.

It's saying: 'The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:'

and then goes on to list most of my static files (images, css, js), and says to specify a cache for more than a week.

In my app.yaml file, I have this: default_expiration: "21d 1h" which doesn't seem to be doing anything.

Does anyone have any ideas on how I can cache the files it's talking about, or is this an issue with using Bottle on AppEngine?

Was it helpful?

Solution

If you have this in your code:

@bottle.route('/static/:filename#.*#')
def static(filename):
    return bottle.static_file(filename, root='./static/')

you can add:

response.headers['Cache-Control'] = 'public, max-age=SECONDS'

in front of the return to enable caching in the browser. This also works for dynamically generated pages as long as you don't use cookies or GET parameters.

But if you can, you should let GAE serve static files directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top