This is a very experimental script setup, feel free to modify, do what you wish, you'll need to take these instructions with a pinch of salt. Its designed to allow you to annotate css/scss/less etc files and then using postcss will generate
*.critical.css
files which can then be inlined using server side includes.
- Skim through the code, updating all the paths/folder structures etc to your requirements.
- Add the extra dependencies to your node setup
- run
node split-critical.js
- or add a script alias in your package.json fornpm run criticalcss
for example. - This will generate a minified
globals.critical.css
for you to use via SSIs and any other tagged files
Simply wrap your critical code around comments e.g
/*! critical:start */
background: red;
/*! critical:end */
We recommend using /*!
style comments as most minification systems strip out the comments but preseve these.
If you want to extract a section into a seperate file simply add critical:start:about
for example to the end to make a about.critical.css
- This was built using Laravel Mix - but should be similar for Elixir and others.
- This doesn't real with autoprefixing, scss compilation or anything, and should be the last script that should run in your chain.