1

I would like to make a js file external for my client... for example, I will give him a link like this:

http://mydomain.com/yourjs/this_is_your.js

But I may update the this_is_your.js and deliver to the user. So, my question is... how can I ensure the user get the latest .js file... So, I have an idea, when I made a new version, I just upload the latest this_is_your.js to the server, then when the web page polls again, the latest .js received. It works, but I would like something more generic... is that technically achievable? Any advices? Thank you.

Petteri H
  • 11,779
  • 12
  • 64
  • 94
Tattat
  • 15,548
  • 33
  • 87
  • 138

2 Answers2

1

You could do the same as GWT does. Have a small file (nocache.js) that wont be cached. In that file you refer to your latest version of your js file. Each version of the actual script has an unique name and therefore it can be cached.

Dynamically load a JavaScript file

How do I include a JavaScript file in another JavaScript file?

Community
  • 1
  • 1
Petteri H
  • 11,779
  • 12
  • 64
  • 94
0

One problem I see with your scheme is that the version of javascript a client has is subject both to what you serve and to how recent the client's cached version of it is... Perhaps you can wrap your script file in a client-side request that takes into account a cookie that you can make obsolete when a new version is out. Just an idea, but I would worry about the performance.

davecoulter
  • 1,806
  • 13
  • 15