Response headers and caching #120
-
Hi, my very basic server is serving some html (rendered template using microdot_utemplate) and a background image. The image isnt caching in my browser (Chrome), and my reading suggests I put some headers into my response such as Cache-Control: max-age=31536000 but I have no idea how. I couldn't find any examples in the docs or examples. Some code snippets: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The docs that apply to this are here: https://microdot.readthedocs.io/en/latest/intro.html#the-three-parts-of-a-response How are you serving your image? Because the example that you posted is for your HTML, but you want to cache the image. |
Beta Was this translation helpful? Give feedback.
-
I just realized that if you are using @app.get('/image.jpg')
def image(request):
return send_file('/static/image.jpg', max_age=31536000) Hope this helps! |
Beta Was this translation helpful? Give feedback.
I just realized that if you are using
send_file()
to serve your image, it wasn't easy to include aCache-Control
header. I have now added amax_age
argument tosend_file()
that you can use to easily indicate what the cache duration is.Hope this helps!