FEATURE: Automatically force a full refresh between pages if assets change

This commit is contained in:
Sam 2014-01-14 16:59:08 +11:00
parent 224a34316f
commit fd95dbe75a
6 changed files with 38 additions and 3 deletions

View file

@ -128,7 +128,18 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
}
});
}
}
},
assetVersion: function(prop, val) {
if(val) {
if(this.get("currentAssetVersion")){
this.set("desiredAssetVersion", val);
} else {
this.set("currentAssetVersion", val);
}
}
return this.get("currentAssetVersion");
}.property()
});

View file

@ -4,5 +4,8 @@
Discourse.addInitializer(function() {
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
Discourse.MessageBus.start();
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
Discourse.set("assetVersion",version);
});
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
}, true);

View file

@ -47,6 +47,16 @@ Discourse.URL = Em.Object.createWithMixins({
@param {String} path The path we are routing to.
**/
routeTo: function(path) {
// If somehow our asset version changed, force a full reload of desired path
var desired = Discourse.get("desiredAssetVersion");
if(desired) {
if(Discourse.get("currentAssetVersion") !== desired){
document.location.href = path;
return;
}
}
var oldPath = window.location.pathname;
path = path.replace(/https?\:\/\/[^\/]+/, '');

View file

@ -9,6 +9,7 @@
Discourse.ApplicationRoute = Em.Route.extend({
actions: {
showLogin: function() {
Discourse.Route.showModal(this, 'login');
this.controllerFor('login').resetForm();
@ -80,7 +81,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
});
}
},
}
},
activate: function() {
@ -90,6 +91,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
Discourse.ApplicationRoute.trigger('activate');
});
}
});
RSVP.EventTarget.mixin(Discourse.ApplicationRoute);

View file

@ -37,6 +37,7 @@
Discourse.SiteSettings = PreloadStore.get('siteSettings');
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
Discourse.start()
Discourse.set('assetVersion','<%= Rails.application.assets.digest %>');
</script>
<%= javascript_include_tag 'browser-update.js' %>

View file

@ -37,3 +37,11 @@ end
MessageBus.cache_assets = !Rails.env.development?
MessageBus.enable_diagnostics
digest = Rails.application.assets.digest.to_s
channel = "/global/asset-version"
message = MessageBus.last_message(channel)
unless message && message.data == digest
MessageBus.publish channel, digest
end