Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
grunt-inlinestyles
Advanced tools
A Grunt plugin to inline a selected CSS file. Ideal for inlining critical CSS.
This will take a HTML stylesheet link and inline the target CSS.
This means that:
<link rel="stylesheet" href="/css/stylesheet.css" data-inline="true">
will become:
<style>h1{font-style:italic}</style>
This module does not inline javascript, images or fonts.
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-inlinestyles --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-inlinestyles');
In your project's Gruntfile, add a section named inlinestyles
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
inlinestyles: {
options: {
// Task-specific options go here.
basepath: './',
minify: true,
tag: '[data-inline="true"]'
},
your_target: {
// Target-specific file lists and/or options go here.
files: {
'destination.html': 'source.html'
}
},
},
})
Type: String
Default value: 'process.cwd()'
A string value that is used to indicate the root of your website. 'Absolute' CSS links are relative to this value.
Type: boolean
Default value: true
A boolean that is used to turn minification of the inlined CSS on or off.
Type: String
Default value: '[data-inline="true"]'
A string value that is used to designate a CSS link that is to be inlined.
In this example, the default options are used to inline CSS inside source.html
. So if the source.html
file has the content <link rel="stylesheet" href="/css/stylesheet.css" data-inline="true">
the generated result would contain <style>h1{font-style:italic}</style>
grunt.initConfig({
inlinestyles: {
options: {},
files: {
'destination.html': 'source.html'
}
},
})
In this example, custom options are used to specify a new basepath, disable CSS minification and to add a new inlining tag.
grunt.initConfig({
inlinestyles: {
options: {
basepath: 'subpath',
minify: false,
tag: '[data-inlinethisstyle="true"]'
},
files: {
'destination.html': 'source.html'
}
},
})
Contributions are welcome! Hit me up via @sonniesedge
v0.0.1 Initial release
Copyright (c) 2014 . Licensed under the MIT license.
FAQs
Inline critical CSS into the HTML header
The npm package grunt-inlinestyles receives a total of 5 weekly downloads. As such, grunt-inlinestyles popularity was classified as not popular.
We found that grunt-inlinestyles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.