Gathering detailed insights and metrics for @vue/preload-webpack-plugin
Gathering detailed insights and metrics for @vue/preload-webpack-plugin
Gathering detailed insights and metrics for @vue/preload-webpack-plugin
Gathering detailed insights and metrics for @vue/preload-webpack-plugin
webpack-font-preload-plugin
A webpack plugin to allow preloading or prefetching of fonts.
preload-webpack-plugin
Enhances html-webpack-plugin with link rel=preload wiring capabilities for scripts
webpack-assets-manifest
This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.
@principalstudio/html-webpack-inject-preload
A HTML Webpack plugin for injecting <link rel='preload'>
A Webpack plugin for wiring up `<link rel='preload'>` (and prefetch) - supports async chunks
npm install @vue/preload-webpack-plugin
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
181 Stars
131 Commits
33 Forks
8 Watching
2 Branches
69 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.7%
60,196
Compared to previous day
Last week
3.5%
322,139
Compared to previous week
Last month
14.7%
1,343,272
Compared to previous month
Last year
-33.7%
17,401,431
Compared to previous year
2
This is a fork of preload-webpack-plugin with a number of changes:
Uses a combination of htmlWebpackPluginBeforeHtmlProcessing
and htmlWebpackPluginAlterAssetTags
hooks to inject links as objects rather than strings. This allows for more flexibility when the tags need to be altered by other plugins.
include
option can be an object in the shape of { type?, chunks?, entries? }
. For example, to prefetch async chunks for a specific entry point:
1{ 2 rel: 'prefetch', 3 include: { 4 type: 'asyncChunks', 5 entries: ['app'] 6 } 7}
Added an includeHtmlNames
option so that the plugin is only applied to a specific HTML file.
Drops support for webpack v3.
Drops support for Node < 6.
A Webpack plugin for automatically wiring up asynchronous (and other types) of JavaScript
chunks using <link rel='preload'>
. This helps with lazy-loading.
Note: This is an extension plugin for html-webpack-plugin - a plugin that simplifies the creation of HTML files to serve your webpack bundles.
This plugin is a stop-gap until we add support for asynchronous chunk wiring to script-ext-html-webpack-plugin.
Preload is a web standard aimed at improving performance and granular loading of resources. It is a declarative fetch that can tell a browser to start fetching a source because a developer knows the resource will be needed soon. Preload: What is it good for? is a recommended read if you haven't used the feature before.
In simple web apps, it's straight-forward to specify static paths to scripts you would like to preload - especially if their names or locations are unlikely to change. In more complex apps, JavaScript can be split into "chunks" (that represent routes or components) at with dynamic names. These names can include hashes, numbers and other properties that can change with each build.
For example, chunk.31132ae6680e598f8879.js
.
To make it easier to wire up async chunks for lazy-loading, this plugin offers a drop-in way to wire them up
using <link rel='preload'>
.
This module requires Webpack 2.2.0 and above. It also requires that you're using html-webpack-plugin in your Webpack project.
First, install the package as a dependency in your package.json:
1$ npm install --save-dev @vue/preload-webpack-plugin
Alternatively, using yarn:
1yarn add -D @vue/preload-webpack-plugin
Next, in your Webpack config, require()
the preload plugin as follows:
1const PreloadWebpackPlugin = require('@vue/preload-webpack-plugin');
and finally, configure the plugin in your Webpack plugins
array after HtmlWebpackPlugin
:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin() 4]
When preloading files, the plugin will use different as
attribute depends on the type of each
file. For each file ends with .css
, the plugin will preload it with as=style
, for each file ends
with .woff2
, the plugin will preload it with as=font
, while for all other files, as=script
will be used.
If you do not prefer to determine as
attribute depends on suffix of filename, you can also
explicitly name it using as
:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'preload', 5 as: 'script' 6 }) 7]
In case you need more fine-grained control of the as
atribute, you could also provide a function here.
When using it, entry name will be provided as the parameter, and function itself should return a
string for as
attribute:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'preload', 5 as(entry) { 6 if (/\.css$/.test(entry)) return 'style'; 7 if (/\.woff$/.test(entry)) return 'font'; 8 if (/\.png$/.test(entry)) return 'image'; 9 return 'script'; 10 } 11 }) 12]
Notice that if as=font
is used in preload, crossorigin will be added, otherwise the font resource
might be double fetched. Explains can be found in this article.
By default, the plugin will assume async script chunks will be preloaded. This is the equivalent of:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'preload', 5 include: 'asyncChunks' 6 }) 7]
For a project generating two async scripts with dynamically generated names, such as
chunk.31132ae6680e598f8879.js
and chunk.d15e7fdfc91b34bb78c4.js
, the following preloads
will be injected into the document <head>
:
1<link rel="preload" as="script" href="chunk.31132ae6680e598f8879.js"> 2<link rel="preload" as="script" href="chunk.d15e7fdfc91b34bb78c4.js">
You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using include: 'all'
, or only preload initial chunks with include: 'initial'
:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'preload', 5 include: 'all' // or 'initial' 6 }) 7]
In case you work with named chunks, you can explicitly specify which ones to include
by passing an array:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'preload', 5 include: ['home'] 6 }) 7]
will inject just this:
1<link rel="preload" as="script" href="home.31132ae6680e598f8879.js">
There may be chunks that you don't want to have preloaded (sourcemaps, for example). Before preloading each chunk, this plugin checks that the file does not match any regex in the fileBlacklist
option. The default value of this blacklist is [/\.map/]
, meaning no sourcemaps will be preloaded. You can easily override this:
1new PreloadWebpackPlugin({ 2 fileBlacklist: [/\.whatever/] 3})
Passing your own array will override the default, so if you want to continue filtering sourcemaps along with your own custom settings, you'll need to include the regex for sourcemaps:
1new PreloadWebpackPlugin({ 2 fileBlacklist: [/\.map/, /\.whatever/] 3})
Should you wish to use Resource Hints (such as prefetch
) instead of preload
, this plugin also supports wiring those up.
Prefetch:
1plugins: [ 2 new HtmlWebpackPlugin(), 3 new PreloadWebpackPlugin({ 4 rel: 'prefetch' 5 }) 6]
For the async chunks mentioned earlier, the plugin would update your HTML to the following:
1<link rel="prefetch" href="chunk.31132ae6680e598f8879.js"> 2<link rel="prefetch" href="chunk.d15e7fdfc91b34bb78c4.js">
A demo application implementing the PRPL pattern with React that uses this plugin can be found in the demo
directory.
If you've found an error in this sample, please file an issue: https://github.com/googlechrome/preload-webpack-plugin/issues
Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub.
index.js
contains the primary source for the plugin, test
contains tests and demo
contains demo code.
Test the plugin:
1$ npm install 2$ npm run test
Lint the plugin:
1$ npm run lint 2$ npm run lint-fix # fix linting issues
The project is written in ES2015, but does not use a build-step. This may change depending on any Node version support requests posted to the issue tracker.
preload
resources a user is unlikely to need. This can waste their bandwidth.preload
for the current session if you think a user is likely to visit the next page. There is no
100% guarantee preloaded items will end up in the HTTP Cache and read locally beyond this session.prefetch
and preconnect
. Prefetched resources are maintained
in the HTTP Cache for at least 5 minutes (in Chrome) regardless of the resource's cachability.Copyright 2017 Google, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
153 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More