mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: Automatically force a full refresh between pages if assets change
This commit is contained in:
parent
224a34316f
commit
fd95dbe75a
6 changed files with 38 additions and 3 deletions
|
@ -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()
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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?\:\/\/[^\/]+/, '');
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
Discourse.ApplicationRoute = Em.Route.extend({
|
||||
|
||||
actions: {
|
||||
|
||||
showLogin: function() {
|
||||
Discourse.Route.showModal(this, 'login');
|
||||
this.controllerFor('login').resetForm();
|
||||
|
@ -80,16 +81,17 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
|||
});
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
this._super();
|
||||
Em.run.next(function() {
|
||||
Em.run.next(function() {
|
||||
// Support for callbacks once the application has activated
|
||||
Discourse.ApplicationRoute.trigger('activate');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
RSVP.EventTarget.mixin(Discourse.ApplicationRoute);
|
||||
|
|
|
@ -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' %>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue