1

I'm trying to avoid caching my Html files. I've tried to work with rev & rev-replace. the result is that only file names are changed but the file's references in the stateprovider aren't changed so it is been resulted with files not found error.

this is part of my config.js which has the stateProvider:

$stateProvider .state('landingPage', { url: "/home", templateUrl: "views/landingPage/landingPage.html", })

this is part of my gulp file:

 gulp.task('copyHtml', ['copyAll','useRef'], function () {
return gulp.src('app/views/**/*.html')
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(rev())
.pipe(revReplace())
.pipe(gulp.dest('dist/views'));
});

how do i change the files reference in the config.js?

The content is not refreshing only on mobile (chrome on android). I've tried to change the html files's names manually and in the stateProvider but it dosn't work either.

How do i avoid browser caching???

thanks

1 Answers1

0

The browser will cache until you change the URI of the templates.

A solution is to store a value, which changed at each build of the project (gulp).

For example:

var build_id = $val_to_generate$;

Now in the controller you defined the urls of the template used:

$scope.urls = {
  template1: "http://adazdazkdaz/template1.html?v=" + build_id
}

Now in the template associated to the controller, use:

 <div ng-include="urls.template1"></div>

The pages won't be cached anymore.

You can do that for the js files too

  • but how do i do that with gulp? how do i add the build_id to the config file? i've succeeded doing that for the js & css but not the html. – stackoverflowNewB May 18 '16 at 14:23
  • in my own, i don't do all my build rules with gulp :/ I've a script in php whose only goal is to generate that file. It generates a file named "build_id". At each call, it opens the file, take the value, and add 1 to the value, then save the file. After that, generate a file named 'globals.tmp.js' for example, that you can use in the gulpfile in the concat rule. – Pierre Emmanuel Lallemant May 18 '16 at 14:32
  • does any one has a gulp solution for this problem? – stackoverflowNewB May 19 '16 at 08:40