Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom attribute support for preload/prefetch #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/async-chunk-resource-hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const addAsyncChunkResourceHints = (chunks, options) => {
[])
.forEach(file => {
if (optionsMatch(options.preload, file)) {
hints.push(createResourceHint('preload', getRef(file)));
hints.push(createResourceHint('preload', getRef(file), options.preload.attrs));
} else if (optionsMatch(options.prefetch, file)) {
hints.push(createResourceHint('prefetch', getRef(file)));
hints.push(createResourceHint('prefetch', getRef(file), options.prefetch.attrs));
}
});
return hints;
Expand Down
5 changes: 3 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const DEFAULT_HASH = {
};
const DEFAULT_RESOURCE_HINT_HASH = {
test: [],
chunks: 'initial'
chunks: 'initial',
attrs: {}
};
const DEFAULT_CUSTOM_HASH = {
test: [],
Expand All @@ -26,7 +27,7 @@ const DEFAULT_OPTIONS = {
removeInlinedAssets: true,
custom: []
};
const POSSIBLE_VALUES = ['chunks', 'attribute', 'value'];
const POSSIBLE_VALUES = ['chunks', 'attribute', 'value', 'attrs'];

const normaliseOptions = options => {
if (!options) return DEFAULT_OPTIONS;
Expand Down
4 changes: 2 additions & 2 deletions lib/initial-chunk-resource-hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const addInitialChunkResourceHints = (options, tags) => {
.reduce((hints, tag) => {
const scriptName = getScriptName(options, tag);
if (optionsMatch(options.preload, scriptName)) {
hints.push(createResourceHint('preload', getRawScriptName(tag)));
hints.push(createResourceHint('preload', getRawScriptName(tag), options.preload.attrs));
} else if (optionsMatch(options.prefetch, scriptName)) {
hints.push(createResourceHint('prefetch', getRawScriptName(tag)));
hints.push(createResourceHint('prefetch', getRawScriptName(tag), options.prefetch.attrs));
}
return hints;
},
Expand Down
6 changes: 3 additions & 3 deletions lib/resource-hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ const shouldAddResourceHints = options => {
options.preload.test.length === 0);
};

const createResourceHint = (rel, href) => {
const createResourceHint = (rel, href, attrs) => {
return {
tagName: 'link',
selfClosingTag: true,
attributes: {
attributes: Object.assign({}, attrs, {
rel: rel,
href: href,
as: 'script'
}
})
};
};

Expand Down