How to update partial views when updating appCache?

I use angularjs routing:

angular.module('questionModule', []). config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/questions', { templateUrl: 'partials/questions.htm', controller: QuestionsController }). when('/questions/:Id', { templateUrl: 'partials/questionDetail.htm', controller: QuestionDetailCtrl }). otherwise({ redirectTo: '/questions' }); } ]); 

on this page:

 <html ng-app="questionModule" manifest="AngularManifest.appcache" > <head> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> <script src="question.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <script src="appCacheBootstrap.js" type="text/javascript"></script> </head> <body> <h2>This example uses angular js routing to display partial views</h2> <div ng-view></div> </body> 

However, when I make changes to one of the partial view files and update the manifest file to update the application cache, this change does not appear. I need to access chrome: // appcache-internals / and delete the application cache to see the updates. How to do it automatically? It seems that the application cache updates correctly when im is on a page that does not use routing.

Here's how I handle manifest file changes:

 $(function () { if (window.applicationCache) { applicationCache.addEventListener('updateready', function () { console.log("appcache status: " + window.applicationCache.status); if (window.applicationCache.status == window.applicationCache.UPDATEREADY) { window.applicationCache.swapCache(); if (confirm('A new version of this site is available. Load it?')) { window.applicationCache.update(); window.location.reload(); } } }); } { console.log("null window.applicationCache"); } }); 

When I am on the routed page page, augularjs.applicatonCache is null.

+4
source share
2 answers

Did you miss the 'else' before the curlies containing the message "null window.applicationCache"?

If it were the correct fragment, it would be:

 $(function () { if (window.applicationCache) { applicationCache.addEventListener('updateready', function () { console.log("appcache status: " + window.applicationCache.status); if (window.applicationCache.status == window.applicationCache.UPDATEREADY) { window.applicationCache.swapCache(); if (confirm('A new version of this site is available. Load it?')) { window.applicationCache.update(); window.location.reload(); } } }); } else{ console.log("null window.applicationCache"); } }); 

Otherwise, you printed a null applicationCache message each time, regardless of whether the cache is active or not. Do not believe everything that you read in the console :).

+2
source

It turns out that because I ran the site through the asp.net development server, and not IIS, it did not work. I suspect the development server has added headers so that it does not work.

0
source

Source: https://habr.com/ru/post/1499778/


All Articles