Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit a3089d0

Browse files
committed
fix potential loading issue
should only add one preload for each font, as multiple preload will cause multiple downloads
1 parent 99c5dab commit a3089d0

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ plugins: [
7373

7474
When preloading files, the plugin will use different `as` attribute depends on the type of each
7575
file. For each file ends with `.css`, the plugin will preload it with `as=style`, for each file ends
76-
with `.woff`, `.woff2`, `.eot`, `.otf` or `.ttf`, the plugin will preload it with `as=font`, while
77-
for all other files, `as=script` will be used.
76+
with `.woff2`, the plugin will preload it with `as=font`, while for all other files, `as=script`
77+
will be used.
7878

7979
If you do not prefer to determine `as` attribute depends on suffix of filename, you can also
8080
explicitly name it using `as`:
@@ -100,6 +100,7 @@ plugins: [
100100
rel: 'preload',
101101
as(entry) {
102102
if (/\.css$/.test(entry)) return 'style';
103+
if (/\.woff$/.test(entry)) return 'font';
103104
if (/\.png$/.test(entry)) return 'image';
104105
return 'script';
105106
}

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PreloadPlugin {
7676
let asValue;
7777
if (!options.as) {
7878
if (entry.match(/\.css$/)) asValue = 'style';
79-
else if (entry.match(/\.(?:eot|otf|ttf|woff2?)$/)) asValue = 'font';
79+
else if (entry.match(/\.woff2$/)) asValue = 'font';
8080
else asValue = 'script';
8181
} else if (typeof options.as === 'function') {
8282
asValue = options.as(entry);

0 commit comments

Comments
 (0)