Here is what we do in pylons 1.0 ( not pyramid ) but I am sure you can
apply similar approach to pyramid.

1) introduce media_URL in your development.INI. set it to say /media ( or
whatever context you use for getting to these static files)

2) write a URL helper in your helpers.py e.g

def media_url (static_url):
       # use the config.media_URL to return the static URL
        # e.g /media/image1.jpg or /media/js/script.js or
/media/CSS/style.CSS

3) in your html use a URL helper to generate the URL e.g using jinja2 syntax
<IMG SRC="{{ h.media_url ('image1.PNG') }}" />

4) using a deploy script you can time stamp the media folder . you can also
optimize your static resources in this step e.g minify JS,combine JS, etc.
But at the end you are creating a build time stamp folder e.g
/media/build-20130101104701

5) the deploy script should modify the development.INI and change the
media_URL property to this new folder.

We also use the above approach to serve the static resources from CDN (
infact more than 1 CDN ) by changing the media_url to the CDN Based URL e.g:

Media_URL = http://cdn1.example.com/media/build-201301010101

Hope this helps.

Ravi
On Sep 4, 2013 11:28 AM, "Michael Merickel" <[email protected]> wrote:

>
> 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.
>

-- 
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.

Reply via email to