5

The RESTful angular application in Microsoft Edge Browser Caching

 2 years ago
source link: https://www.codesd.com/item/the-restful-angular-application-in-microsoft-edge-browser-caching.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The RESTful angular application in Microsoft Edge Browser Caching

advertisements

I'm developing a Webapp that uses Angular.js which server by a RESTful API. During the development phase I use my preferred browser which is Chrome, but I just ran some tests in Edge and made some interesting discoveries.

I noticed that the result of a call to the RESTful server was seemingly returning incorrect data. Upon closer inspection I realised that this was due to the Edge browser loading the results from Cache rather than making the call to get the latest and correct results. What's more I realised that I can remove whole functions from my Angular app file and Edge doesn't seem to complain!

The angular function in question:

$http.get(frontbaseurl+'/users/auth_user.json').then(function(response){})

I've read a few responses to questions on SO that suggest various ways to force Edge to not cache results (for example adding a data stamp to the get url), but it sounds hacky and in my case it didn't work anyway.

I can't quite believe my findings. The coder in me wants to shrug my shoulders and put this down to yet another catastrophe from MS, but I can't ignore the fact some unfortunate individuals may have no other choice and could experience errors if they use my web app.

Anyone else experienced this?


As a web developer, I really appreciate that browsers put heavy cache to avoid unnecessary requests to my server and help my users to have a faster, and better, experience.

There are many techniques to request the browser to stop caching, but please, don't do that! Caching is very helpful and there are smart ways to prevent the browser to use old content.

I've read a few responses to questions on SO that suggest various ways to force Edge to not cache results (for example adding a data stamp to the get url), but it sounds hacky and in my case it didn't work anyway.

I believe that you missed the point here. You don't add the a data stamp to the get url. You need to add it to the file url.

Wrong:

$http.get(frontbaseurl+'/users/auth_user.json?v=20160510').then(function(response){})

Right:

<script src="/path/to/services.min.js?v=20160510"></script>

Adding the querystring to the file name should be part of your build action.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK