bcrowell2 has asked for the wisdom of the Perl Monks concerning the following question:
I have a perl cgi application that is kind of big and slow, and I'm trying to push as much of the work as possible off onto the client, using javascript. I have a bunch of the code in a particular file, call it foo.js, and the cgi generates html code like this:
The good thing about this is that it gives good performance. Even if foo.js gets pretty big, the user's browser will have it cached, so there won't be any load on the server to keep on sending the code, and the client won't have to wait for the code to come over the internet.<script type="text/javascript" src="foo.js"></script>
However, it gets awkward when I want to change foo.js, because the user is going to have a cached copy. If the change isn't vital, it's not a big deal -- some users will be using the old code for a while, until their cached copy expires. But it's possible that I will, for example, take more functionality out of the perl cgi and shift it into foo.js, in which case it breaks if the user is using the old, cached version of foo.js.
IIRC, there's some way to configure apache so that it won't cache certain files, but I actually like the caching. Is there some technique I can use in the javascript code that will check whether it's the right version, and fix itself dynamically if necessary? For example, the cgi could emit html code like this:
Then foo.js could have code like<script>var version_of_foo_must_be = 2.37;</script> <script type="text/javascript" src="foo.js"></script>
var what_version_i_am = 2.36; if (what_version_i_am<version_of_foo_must_be) { // scream and panic }
My real question is what the "scream and panic" should be. It could just display a message to the user, like "Please clear your cache," but that would probably confuse a lot of users. Is there any way I could just dynamically make the code update itself?
TIA!
Ben
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: cache js code, but detect when it's changed?
by Corion (Patriarch) on Oct 06, 2007 at 18:03 UTC | |
by bcrowell2 (Friar) on Oct 06, 2007 at 20:22 UTC | |
| |
Re: cache js code, but detect when it's changed?
by Cop (Initiate) on Oct 06, 2007 at 18:16 UTC | |
by Chady (Priest) on Oct 06, 2007 at 18:56 UTC | |
by Cop (Initiate) on Oct 06, 2007 at 19:14 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |