0

I am using Angular JS 1 as my view for my project. With each deployment i have to clear cache to make my js changes visible. I cannot ask my client to do the same. I am caching this request for the first time when a new user access the applications because css/images are not going to change that frequently as respect to js files. please let me know if there is any way that we can load only the changed cc/image/js files in user browser and use rest of them from cache.

Hack-R
  • 19,705
  • 11
  • 63
  • 110
  • Are you also using nginx or apache? You can try to see if nginx's caching works. – Gavin Haynes Nov 14 '16 at 01:44
  • So are you saying you _want_ a fresh reload for JS resources or you _don't_ want a fresh reload for JS resources? – Tim Biegeleisen Nov 14 '16 at 01:47
  • 1
    Possibly relevant: http://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files – Tim Biegeleisen Nov 14 '16 at 01:49
  • The solution for this issue is writing a interceptor factory to add a query string to every template request, usually the url ended with ‘.html’ (but in this case, all the templates located in ‘views/*.html’). ...views/app.html?t=1467948997000 However, I’m not gonna use a regular timestamp as suggested in the last comment of the first StackOverflow post (by using new Date() function), but the timestamp of the latest Git commit because it keeps changing automatically during the development and stay the same once we deployed to production. You can use app version or whatever. – Japar Sathik Oct 19 '19 at 08:58
  • code here you go : 'use strict'; angular.module('preventTemplateCache') .factory('preventTemplateCache', function($injector) { var ENV = $injector.get('ENV'); return { 'request': function(config) { if (config.url.indexOf('views') !== -1) { config.url = config.url + '?t=' + ENV.build; } return config; } } }) .config(function($httpProvider) { $httpProvider.interceptors.push('preventTemplateCache'); }); – Japar Sathik Oct 19 '19 at 08:59

0 Answers0