[Javascript] Auto reloading JS files on change?

Roger Roelofs rer at datacompusa.com
Mon Jun 2 15:23:21 CDT 2008


Scott,

On Jun 2, 2008, at 4:14 PM, Scott Reynen wrote:

> On [Jun 2], at [ Jun 2] 1:19 , Roger Roelofs wrote:
>
>> Mark,
>>
>> On Jun 2, 2008, at 8:52 AM, Rees, Mark wrote:
>>
>>> I have the following in an HTML file that is
>>> echo'd to the browser via PHP code.
>>>
>>> <script src="ajax/players.js"
>>> type="text/javascript"></script>
>>>
>>> But whenever this, and other, .js files are
>>> modified the user must know to hit the refresh
>>> button on his browser.
>>>
>>> I've been looking for a way to reload the JS files
>>> on changes, and I've come across the last-modified
>>> header element, but not sure how to implement this.
>>
>> Have you looked at JSONP?
>> http://simonwillison.net/2005/Dec/16/json/
>>
>> It basically works by letting you specify a function for the inserted
>> script to call so you can know when it has loaded and process any  
>> data
>> it contains.  The recent version of jQuery has support built in for
>> this.
>
> Executing external JavaScript loaded via AJAX is an awfully convoluted
> way to avoid caching.  Simply changing the name of the JavaScript file
> will force a new download by avoiding the cached version associated
> with the original name.  If you want to learn how caching works,
> here's a decent tutorial:
>
> http://www.mnot.net/cache_docs/

I'm familiar with caching.  My impression was that the OP was using  
php to write javascript on the fly and wanted the page to auto-reload  
the script in some fashion.

Roger
--
Roger Roelofs
Datacomp Appraisal Services
3215 Eaglecrest, NE
Grand Rapids, MI  49525




More information about the Javascript mailing list