-2

I have a simple java script single page app using requirejs, underscore, jQuery for serving help material, no server pages. I am new to javascript single page apps, I want to know how to force browser to reload my files on changes?

I am serving my files from amazons3 not with apache or any other server which I can restart. I not asking about crtl+f5 or other commands or apply cache headers, what is the practice for javascript single page apps to reload files?

Single page apps are meant to download all the html, css & javascript files to client side once and javascript updates data from server on user actions and not to download html from server for every request.

When I tried my single page app, it worked fine, when I added some changes to js files I could not see the changes, so how can I configure javascript single page apps to download modified files.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user884424
  • 573
  • 1
  • 12
  • 33

2 Answers2

0

Take a look at this:

http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/

It's a guide to setting cache headers. If you don't want browsers to cache your files you need to tell them, using headers on the responses you serve.

If this is just for development purposes however then just clear the cache. If you use Chrome open the developer tools, and then you can clear the cache by right clicking on the refresh button, it's 2 clicks, so not exactly a chore!

James Gaunt
  • 14,631
  • 2
  • 39
  • 57
  • @adeneo ,@leukhin in my case its different because i don't have a server in my ctrl I am serving my files from amazon s3.I know about ctrl-f5, ctrl... etc but when users are looking at my site I cannot ask everybody to do the same, I asking how to from javascript app force browsers to reload all files and not to use the cached versions. I dont want to use cache header like server pages for changing data, in my case only when I update some js files for a new feature or update templates I need browser to load these and not use cache versions. – user884424 Apr 05 '14 at 21:21
  • I see, well I'd expect you can control cache headers from Amazon S3. Google of 'Amazon S3 Cache Control Header' throws up plenty of help. Alternatively one Javascript solution would be to use JS to dynamically change the URL for the scripts by appending a random number / timestamp as a query string variable (e.g. .../myscript.js?r=12232412)... which would make the browser think it was a different file. Just do this every time your pages are rendered. AFAIK there is now way to programatically clear the actual cache from JS, not in any sort of cross browser compatible way certainty. – James Gaunt Apr 06 '14 at 13:53
0

The browser only knows what the Server tells it. Republish (or stop/start) your server and it'll pickup your file changes and tell the browser to begin using them.