问题
My attempt at matching a regex as directory name in app.yaml doesn't work :
- url: /v1_.*
static_dir: static/v1
expiration: "364d"
Although this official spec says regex syntax is supported. Is there a way to make this work ?
I.e. /v1_2014-01-29/img/logo.png
should match the static file /static/v1/img/logo.png
.
Trivia
I use Google App Engine to serve a Go webapp.
I'd like to maximize browser cache longevity, minimize number of requests and still serve the fresh versions of my css/js/png, and I believe revving filenames is a best practice to achieve this. Also as adding a variable querystring (/v1/img/logo.png?2014-01-29
) might cause proxy and cache problems, I prefer to show a variable directory name (/v1_2014-01-29/img/logo.png
), pointing to the same underlying server dir.
回答1:
Seems to me that whatever part of the URL that is beyond the match of the url definition (which matches from the start) is appended to the static_dir.
So the following handler should match /v1_2014-01-29/img/logo.png
if the file path is static/v1/img/logo.png
(tried with Python):
- url: /v1_(\d+-?)+
static_dir: static/v1
回答2:
After olivierdm's answer I changed my yaml into :
- url: /v1_.*_
static_dir: static/v1
expiration: "364d"
and my html templates to produce /v1_2014-01-29_/img/logo.png
.
Basically, the extra arbitrary character underscore _
forces .*
to match 2014-01-29
, not the empty string.
Now every time I want the visitors to reload the static files, I just change the date in the tempating (I don't touch the app.yaml anymore). Also, any accidental request to an "outdated" URL will still succeed and serve the fresh resource.
来源:https://stackoverflow.com/questions/21443688/app-yaml-wildcard-in-url-with-static-dir