mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -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.addInitializer(function() {
|
||||||
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
|
Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development";
|
||||||
Discourse.MessageBus.start();
|
Discourse.MessageBus.start();
|
||||||
|
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
|
||||||
|
Discourse.set("assetVersion",version);
|
||||||
|
});
|
||||||
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
|
@ -47,6 +47,16 @@ Discourse.URL = Em.Object.createWithMixins({
|
||||||
@param {String} path The path we are routing to.
|
@param {String} path The path we are routing to.
|
||||||
**/
|
**/
|
||||||
routeTo: function(path) {
|
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;
|
var oldPath = window.location.pathname;
|
||||||
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
Discourse.ApplicationRoute = Em.Route.extend({
|
Discourse.ApplicationRoute = Em.Route.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
|
||||||
showLogin: function() {
|
showLogin: function() {
|
||||||
Discourse.Route.showModal(this, 'login');
|
Discourse.Route.showModal(this, 'login');
|
||||||
this.controllerFor('login').resetForm();
|
this.controllerFor('login').resetForm();
|
||||||
|
@ -80,7 +81,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
activate: function() {
|
activate: function() {
|
||||||
|
@ -90,6 +91,7 @@ Discourse.ApplicationRoute = Em.Route.extend({
|
||||||
Discourse.ApplicationRoute.trigger('activate');
|
Discourse.ApplicationRoute.trigger('activate');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RSVP.EventTarget.mixin(Discourse.ApplicationRoute);
|
RSVP.EventTarget.mixin(Discourse.ApplicationRoute);
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
||||||
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
||||||
Discourse.start()
|
Discourse.start()
|
||||||
|
Discourse.set('assetVersion','<%= Rails.application.assets.digest %>');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<%= javascript_include_tag 'browser-update.js' %>
|
<%= javascript_include_tag 'browser-update.js' %>
|
||||||
|
|
|
@ -37,3 +37,11 @@ end
|
||||||
|
|
||||||
MessageBus.cache_assets = !Rails.env.development?
|
MessageBus.cache_assets = !Rails.env.development?
|
||||||
MessageBus.enable_diagnostics
|
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