that is an extremely complex problem for such small problem...

if you are worried about caching, just append a number to the file or
add a date to it.

On Jun 22, 6:48 pm, alex <[EMAIL PROTECTED]> wrote:
> I already have {{ MEDIA_URL }} set in html, css, and js templates and
> that's working great. I would like to start setting far future caching
> headers on media files based on the git abbreviated commit hash for
> each file. i can think of three options for implementing this and
> would appreciate feedback, especially in regard to the processing or
> performance penalties any of these approaches may incur. i've
> implemented proof-of-concept versions of all of them in development
> and they at least accomplish what I want, though I haven't yet done
> any benchmarking.
>
> as part of the production deployment process, a script is run which
> essentially does the following: for every static media file, find the
> git abbreviated commit hash which looks like "857vb4". the results are
> written to disk as a python dictionary:
>
> STATIC_ASSETS = {
>     "/media/image/button.png": "/857vb4",
>     "/media/image/submit.png": "/219cb3",
>     etc.
>
> }
>
> the dictionary has approx 100 entries and may grow to 200.
>
> all of the approaches below generate html like this:
>
> <img src="http://media.example.com/857vb4/media/image/button.png";>
> <img src="http://media.example.com/219cb3/media/image/submit.png";>
>
> but the actual paths on disk do not include version numbers. apache
> has a re-write rule which removes the revision information, so that
> clients can be told to cache the static files for a long time into the
> future because whenever the file changes, the revision number in the
> url will change. here are some ways i've come up with for adding the
> revision info to the static file urls.
>
> 1) simple string filter
> templates look like this: <img src="{{ MEDIA_URL }}{ file_version|
> get_file_version:"/media/image/button.png" }}">
> and the template filter is approx:
>
> @register.filter
> @stringfilter
> def get_file_version(value, arg):
>     if arg in STATIC_ASSETS:
>         value = STATIC_ASSETS[arg] + arg;
>     else:
>         value = arg;
>     return value
>
> 2) simple custom template tag
> templates look like: <img src="{{ MEDIA_URL }}{% get_file_version "/
> media/image/button.png" %}">
>
> template tag code:
>
> @register.simple_tag
> def get_file_version(arg):
>     value = arg
>     if arg in ASSET_LIST:
>         value = ASSET_LIST[arg] + arg;
>     return value
>
> The third option would be a custom context processor which adds
> template variables to each page that are tied to the filename.
>
> Are these approaches reasonable or do they incur too much processing
> for, say, a page that has 10 or 20 static files (images, js, css)? Is
> there a better way I'm overlooking? I'm trying to avoid approaches
> which rename files on disk or do find-and-replace operations on
> template files.
>
> Any feedback appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to