jantimon/resource-hints-webpack-plugin

Needs `as` attribute

Opened this issue · 1 comments

See here: https://www.smashingmagazine.com/2016/02/preload-what-is-it-good-for/#loading-of-late-discovered-resources
If the as attribute is omitted from the preload, it has lower priority or isn't even used at all (Chrome shows: was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.

beheh commented

This seems to work for me locally. The plugin is choosing the attribute based on the extension:

var preloadDirective = {
'.js': 'script',
'.css': 'style',
'.woff': 'font',
'.woff2': 'font',
'.jpeg': 'image',
'.jpg': 'image',
'.gif': 'image',
'.png': 'image',
'.svg': 'image'
};

And it's correctly set in the fixture (only for preload though - prefetch doesn't have an as attribute).

<link rel="preload" href="bundle.js" as="script"><link rel="prefetch" href="bundle.js"></head>