GoogleChromeLabs / preload-webpack-plugin

Please use https://github.com/vuejs/preload-webpack-plugin instead.
Apache License 2.0
2.15k stars 144 forks source link

How to preload Google Fonts from CDN #95

Closed Carrzw closed 5 years ago

Carrzw commented 5 years ago

Sorry at first I am not sure if it's proper to have this question here, I already asked this on StackOverflow, but I think maybe I could get more helps here.

So maybe this should not be the issue for this plugin, but more related to the css-loader and file-loader,

exports.preloadWebpack = new PreloadWebpackPlugin({
  rel:           'preload',
  include:       'allAssets',
  fileWhitelist: [/\.woff/, /\.woff2/, /\.ttf/],
  as:            'font',
});

It seems this only works for assets bundled by file-loader? So I @import fonts by google CDN, and it's from external source, so file-loader won't handle this part and so this plugin cannot work on that either, right? Anyway this is just my guess, any help is appreciated!!!

jeffposnick commented 5 years ago

This plugin can only be used with assets that are part of your local webpack compilation. Given that Google Fonts URLs are not included in your webpack build, I'd recommend using a different technique for preloading them if you need—prehaps look up the URLs ahead of time and then include the appropriate <link rel="preload"...> HTML in your html-webpack-plugin's template.