diff --git a/packages/autoupdate/autoupdate_cordova.js b/packages/autoupdate/autoupdate_cordova.js index 85b1c3030d..3451580229 100644 --- a/packages/autoupdate/autoupdate_cordova.js +++ b/packages/autoupdate/autoupdate_cordova.js @@ -90,17 +90,20 @@ var onNewVersion = function () { _.each(manifest, function (item) { if (! item.url) return; - var uri = encodeURI(urlPrefix + item.url); + + // Add a cache buster to ensure that we don't cache an old asset. + var uri = encodeURI(urlPrefix + item.url + '?' + Random.id()); // Try to dowload the file a few times. var tries = 0; var tryDownload = function () { + console.log('downloading', uri) ft.download(uri, versionPrefix + item.url, function (entry) { if (entry) { afterAllFilesDownloaded(); } }, function (err) { - // It failed, try again if we have tries less than 5 times. + // It failed, try again if we have tried less than 5 times. if (tries++ < 5) { tryDownload(); } else { diff --git a/packages/autoupdate/package.js b/packages/autoupdate/package.js index fbfcebbe8b..dcfec1bea5 100644 --- a/packages/autoupdate/package.js +++ b/packages/autoupdate/package.js @@ -10,7 +10,7 @@ Cordova.depends({ Package.on_use(function (api) { api.use('webapp', 'server'); - api.use(['deps', 'retry'], 'client'); + api.use(['deps', 'retry', 'random'], 'client'); api.use(['livedata', 'mongo-livedata', 'underscore'], ['client', 'server']); api.use('deps', 'client'); api.use('reload', 'client', {weak: true}); diff --git a/tools/client/meteor_cordova_loader.js b/tools/client/meteor_cordova_loader.js index 8e8f0a61ad..112a53b560 100644 --- a/tools/client/meteor_cordova_loader.js +++ b/tools/client/meteor_cordova_loader.js @@ -93,9 +93,23 @@ document.getElementsByTagName('head')[0].appendChild(styleTag); }; + var stripLeadingSlash = function (p) { + if (p.charAt(0) !== '/') + throw new Error("bad path: " + p); + return p.slice(1); + }; + var loadAssetsFromManifest = function (manifest, urlPrefix) { + // Set the base href so that relative paths point to the correct version + // of the app. + var newBase = document.createElement("base"); + newBase.setAttribute("href", urlPrefix); + document.getElementsByTagName("head")[0].appendChild(newBase); + each(manifest, function (item) { - var url = urlPrefix + (item.url ? item.url.substring(1) : ''); + // We want to use relative paths so that our base href is taken into + // account. + var url = item.url ? stripLeadingSlash(item.url) : ''; if (item.type === 'js') queue.push(function () { loadScript(url);