Firstly, you should use care with long Expires
headers, since you're making an absolute guarantee to the client that the content will not change for the time you specify. Personally I'd prefer to support conditional requests and ETags - these still require a request round trip, but don't need to transfer any content in the case that the resource hasn't changed. Note that if you do use long Expires
times then when the resources do change, you'll need to change their URL, which is a pain.
There are two cases for serving content from PA - content returned directly from your Flask script and files in directories specified by the Static Files section of the Web tab on your Dashboard.
In the former case, you can easily write some Python code to add an appropriate Expires
header. There may be an extension or snippet that can help you, but it's really easy to do manually. For example, the Flask app below returns a fixed response and indicates to the browser it will expire in 100 days:
import datetime
import flask
app = flask.Flask(__name__)
@app.route('/')
def hello():
expiry_time = datetime.datetime.utcnow() + datetime.timedelta(100)
response = flask.make_response("Hello from flask!")
response.mimetype = "text/plain"
response.headers["Expires"] = expiry_time.strftime("%a, %d %b %Y %H:%M:%S GMT")
return response
Note that the format of the date string in the Expires
header is defined in the RFC 2616.
Anything you declare as static content and allow PA to serve on your behalf gets served directly by nginx, and I suspect most of the time you can rely on it to get things right. It probably won't use an Expires
header, but it should support conditional requests and ETags. If you really want to support Expires
headers on these files, you'll probably have to stop using PA's static file support and serve everything through Flask.
EDIT
As an aside, nginx does have a module for setting an Expires
header, so it's possible that the PA devs would consider adding a feature to allow users to specify a custom expiry time for their static content. However, I wouldn't have thought this would be regarded as particularly high priority, especially given the stability improvements underway at present.