how to cache django javascript message file ('/jsi18n/') with apache (production setup)

476 views
Skip to first unread message

alain D.

unread,
Mar 5, 2008, 12:58:57 PM3/5/08
to Django users
Hi,

If there a simple apache configuration that is know to make browser
cache the javascript message file ('jsi18n') in a standard apache
django production setup ?
I've tried to add :

<Location "/jsi18n/">
ExpiresActive on
ExpiresDefault "access plus 1 month"
</Location>

To my django virtual host and then I get this headers in the reply :
HTTP/1.1 200 OK
Date: Wed, 05 Mar 2008 17:54:25 GMT
Server: Apache
Vary: Accept-Language,Cookie,Accept-Encoding
Content-Type: text/javascript
Content-Language: en-us
Cache-Control: max-age=2592000
Expires: Fri, 04 Apr 2008 17:54:25 GMT
Connection: close

But my browser (firefox) keeps requesting this file for every
(html) request that includes it ...

Any idea ? Help ?

Regards,

Alan

jfine

unread,
Mar 5, 2008, 5:33:53 PM3/5/08
to Django users
On Mar 5, 5:58 pm, "alain D." <alain.delieu...@free.fr> wrote:
> Hi,
>
> If there a simple apache configuration that is know to make browser
> cache the javascript message file ('jsi18n') in a standard apache
> django production setup ?

[snip]

> To my django virtual host and then I get this headers in the reply :
> HTTP/1.1 200 OK
> Date: Wed, 05 Mar 2008 17:54:25 GMT
> Server: Apache
> Vary: Accept-Language,Cookie,Accept-Encoding

Thank you for sending clear and precise information. I think the
problem lies with the Vary: header. Are you sure you want to tell the
cache that the javascript depends on the cookie?

Hope this help.
--
Jonathan

Malcolm Tredinnick

unread,
Mar 5, 2008, 6:21:08 PM3/5/08
to django...@googlegroups.com

It has to depend on the localisation cookie. The jsi18n URL is mapped to
the django.views.i18n.javascript_catalog view. This produces a file
containing the translation strings for the requester's currently active
language. Since the currently active language can be stored in the
language cookie, the cache for that URL must depend vary on "cookie".

This is fairly tricky to work around, since web pages need a single URL
they can refer to in order to pull in the translation file, regardless
of the user's active language choice for that particular request.

Short version: it's pretty much impossible to cache that file directly.

I have a couple of ideas to try and experiment with in the future, but
it's not the highest priority item at the moment.

Regards,
Malcolm

--
Borrow from a pessimist - they don't expect it back.
http://www.pointy-stick.com/blog/

alain D.

unread,
Mar 6, 2008, 5:56:02 AM3/6/08
to Django users
Thanks for the precise reply ... looking forward to know about your
ideas on this matter ...

wtanaka.com

unread,
Aug 26, 2009, 10:25:28 AM8/26/09
to alain D., django...@googlegroups.com
This is a wrapper function and some instructions for enabling caching
of the /jsi18n/ javascript string catalog: http://wtanaka.com/django/jsi18ncache
Reply all
Reply to author
Forward
0 new messages