Gathering detailed insights and metrics for web-resource-inliner
Gathering detailed insights and metrics for web-resource-inliner
Gathering detailed insights and metrics for web-resource-inliner
Gathering detailed insights and metrics for web-resource-inliner
Inlines img, script and link tags into the same file
npm install web-resource-inliner
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
69 Stars
277 Commits
30 Forks
4 Watching
1 Branches
25 Contributors
Updated on 30 Sept 2024
JavaScript (66.24%)
HTML (29.16%)
CSS (4.6%)
Cumulative downloads
Total Downloads
Last day
-8.1%
177,471
Compared to previous day
Last week
-1.1%
1,005,343
Compared to previous week
Last month
2.9%
4,313,548
Compared to previous month
Last year
23.4%
49,089,491
Compared to previous year
5
4
Brings externally referenced resources, such as js, css and images, into a single file.
For example:
1<link href="css/style.css" rel="stylesheet" data-inline >
is replaced with
1<style> 2/* contents of css/style.css */ 3</style>
Javascript references are brought inline, and images in the html and css blocks are converted to base-64 data: urls.
By default, all links and scripts are inlined, plus any images under 8KB, however this behavior can be overrided via several options.
npm install web-resource-inliner
For a number of usage examples, see ./test/spec.js and the associated test.* and test_out.* files in ./test/cases/
Expects options.fileContent to be HTML and creates a new HTML document. callback
will be called on completion or error with arguments ( error, result )
.
Expects options.fileContent to be CSS and creates a new CSS document. callback
will be called on completion or error with arguments ( error, result )
.
fileContent
, requiredThis is the HTML or CSS content to be inlined, you should provide HTML to the html()
method and CSS to the css()
method or you will get errors or garbage output.
inlineAttribute
, string, default data-inline
Sets the attribute that is used to include/exclude specific resources based on the default behavior for the resource type. For example, if scripts
is set to false
, an individual script can be inlined by adding the attribute to the script
tag like <script src="myscript.js" data-inline ></script>
. On the other hand, if images
are set to be inlined by default, a specific image can be excluded by adding -ignore
to the end of the inlineAttribute
like <img src="myimg.png" data-inline-ignore >
. In CSS, a comment is required at the end of the line to perform the same thing, such as /*data-inline*/
or /*data-inline-ignore*/
.
images
, Boolean or Number, default 8
When true, inline images unless they have an exclusion attribute (see inlineAttribute option). When false, exclude images unless they have an inclusion attribute (see inlineAttribute option). When a number, inline images only when the base64 content size is less than the number of KBs. For example, the default is to only inline images less than 8KB.
svgs
, Boolean or Number, default 8
When true, inline SVG <use>
unless they have an exclusion attribute (see inlineAttribute option). When false, exclude SVG <use>
unless they have an inclusion attribute (see inlineAttribute option). When a number, inline SVG <use>
only when the content size is less than the number of KBs. For example, the default is to only inline SVGs less than 8KB.
scripts
, Boolean or Number, default true
When true, inline scripts unless they have an exclusion attribute (see inlineAttribute option). When false, exclude scripts unless they have an inclusion attribute (see inlineAttribute option). When a number, inline scripts only when the base64 content size is less than the number of KBs.
links
, Boolean or Number, default true
When true, inline stylesheet links unless they have an exclusion attribute (see inlineAttribute option). When false, exclude stylesheet links unless they have an inclusion attribute (see inlineAttribute option). When a number, inline stylesheet links only when the base64 content size is less than the number of KBs.
relativeTo
, string, default empty stringDescribes the path relationship between where web-resource-inliner is running and what the relative paths in fileContent
or href/src urls refer to. For example, the tests cases in this package are in test/cases/
so their relative paths start by referring to that folder, but the root of this project and where npm test
runs from is 2 folders up, so relativeTo
is set to test/cases/
in test/spec.js
. Likewise, with href="content.css"
and a relativeTo
of http://github.com/
the resource retrieved would be http://github.com/content.css
.
rebaseRelativeTo
, string, default empty stringDescribes the path relationship between CSS content and the context it will be loaded in. For example, when a CSS file contains url(some-file.png)
and the file is moved from a location in a folder like /css
to /
then the path to the image needs to be changed to url(css/some-file.png)
. In this case, rebaseRelativeTo
would be css
. You probably don't want to set this when you are using html()
.
strict
, Boolean, default false
When strict is true
, a missing resource will cause the inliner to halt and return an error in the callback. The default behavior is to log a warning to the console and continue inlining with the available resources, which is more similar to how a web page behaves.
requestResource
, Function, default undefined
Allows to adjust issued requests. E.g., add authentication tokens to requested URLs. The function is called with { uri, encoding, gzip }
object as its parameter. It can replace builtin node-fetch with your own solution.
scriptTransform
, Function( content, callback ), default undefined
Allows to make changes to scripts before they are inlined, such as minifying. Callback is standard node error first, second argument is transformed value.
linkTransform
, Function( content, callback ), default undefined
Allows to make changes to links before they are inlined, such as CSS pre-and-post-processors. Callback is standard node error first, second argument is transformed value.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Run tests with npm test
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
Found 3/9 approved changesets -- score normalized to 3
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
Score
Last Scanned on 2024-11-25
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