Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satblip/caddd74080c4fe5d33e6 to your computer and use it in GitHub Desktop.
Save satblip/caddd74080c4fe5d33e6 to your computer and use it in GitHub Desktop.
/*
* Decide on your cache-busting strategy. In this example, we use the current timestamp, which will
* force a change every time the app is visited, but not every time the partial is loaded within a
* visit. Even better would be to use a hash of the file's contents to ensure that the file is always
* reloaded when the file changes and never reloaded when it isn't.
*/
var cacheBustSuffix = Date.now();
// Optionally, expose the cache busting value as a constant so other parts of your app can use it.
ngModule.constant("cacheBustSuffix", cacheBustSuffix);
// Configure routing
ngModule.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/', {
//Append our cache busting value as a query parameter when we specify our templates
templateUrl: 'partials/dashboard.html?cache-bust=' + cacheBustSuffix,
controller: "DashboardCtrl"
});
...
$routeProvider.otherwise({redirectTo: '/'});
}]);
/*
* What if we include a partial within another and it's not referenced directly as a route?
* This is one possible approach, though you may want to organize things differently.
*/
ngModule.controller("EnterTimesheetCtrl", [
"$scope", "cacheBustSuffix", // we're using the constant declared above
function EnterTimesheetCtrl($scope, cacheBustSuffix) {
$scope.editableTemplateUrl = "partials/timesheet/editableTimesheet.html?cache-bust=" + cacheBustSuffix;
}
<div ng-include src="editableTemplateUrl"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment