On Wed, Sep 4, 2013 at 1:10 PM, Jonathan Vanasco <[email protected]>wrote:
> <img src="/path/to?{request.app_meta.release}"/>
>
This works but it's not utilizing pyramid's url generation facilities
(static_url/static_path), so I wouldn't consider it a best practice.
It's actually very easy to write your own cache buster in a similar vein by
adding a pregenerator to your static view.
config.registry['cache_buster'] = str(int(time.time()))
def cache_buster(request, elements, kw):
query = kw.pop('_query', {})
if hasattr(query, 'items'):
query = query.items() # because query could be a list of 2-tuples
buster = ('t', request.registry['cache_buster'])
kw['_query'] = list(query) + [buster]
return elements, kw
config.add_static_view('static', 'myapp:static', pregenerator=cache_buster)
This should generate urls such as:
request.static_path('myapp:static/foo.png') # -->
/static/foo.png?t=1378318982
This is off the top of my head so I'm sure someone can encapsulate this
into something nicer but it's not so difficult.
Note that static views are just routes, so you if you don't like query
string cache busters then you could even handle it via a placeholder:
def cache_buster(request, elements, kw):
kw.setdefault('buster', request.registry['cache_buster'])
return elements, kw
config.add_static_view('static/{buster}', 'myapp:static',
pregenerator=cache_buster)
request.static_path('myapp:static/foo.png') # --> /static/1378318982/foo.png
HTH,
- Michael
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.