Skip to content

Commit

Permalink
Don't use <script> tag to pass fingerprinted assets file name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Zavacky committed Oct 9, 2017
1 parent e121efb commit 3104e3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions addon/initializers/asset-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export function initialize(app) {

let assetMapFile = window && window.__assetMapPlaceholder__;

if (!assetMapFile) {
assetMapFile = decodeURIComponent(document.querySelector('[property="ifa:placeholder"]').getAttribute('content'));
}

if (!assetMapFile) {
app.register('service:asset-map', AssetMap);
return;
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ module.exports = {

if (ifaConfig.inline && fs.existsSync(assetFileNamePath)) {
assetMapPlaceholder = fs.readFileSync(assetFileNamePath, {encoding: 'utf-8'});

} else {
if (assetFileName) {
assetMapPlaceholder = `"${fingerprintPrepend}assets/${assetFileName}"`;
assetMapPlaceholder = encodeURIComponent(`${fingerprintPrepend}assets/${assetFileName}`);
}
}

Expand All @@ -69,7 +68,9 @@ module.exports = {
},

contentFor(type, config) {
if (type === 'head-footer' && config.ifa && config.ifa.enabled) {
if (type === 'head' && config.ifa && config.ifa.enabled && !config.ifa.inline) {
return '<meta property="ifa:placeholder" content="__asset_map_placeholder__">';
} else if (type === 'head-footer' && config.ifa && config.ifa.enabled && config.ifa.inline) {
return '<script>var __assetMapPlaceholder__ = __asset_map_placeholder__;</script>';
}
}
Expand Down

0 comments on commit 3104e3b

Please sign in to comment.