├── .editorconfig ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── codeql.yml │ ├── lint.yml │ └── test.yml ├── .gitignore ├── .npmrc ├── History.md ├── LICENSE ├── README.md ├── cli.js ├── index.js ├── jest.config.js ├── package-lock.json ├── package.json ├── src ├── css.js └── dom.js └── test ├── cli.test.js ├── expected ├── cartoon-absolute-expected-print.html ├── cartoon-absolute-expected.html ├── cartoon-expected-minified-alt-print.html ├── cartoon-expected-minified-alt.html ├── cartoon-expected-minified-print.html ├── cartoon-expected-minified.css ├── cartoon-expected-minified.html ├── cartoon-expected.css ├── external-expected-print.html ├── external-expected.html ├── external-extract-expected-print.html ├── external-extract-expected.html ├── external-ignore-expected-print.html ├── external-ignore-expected.html ├── index-before-print.html ├── index-before.html ├── index-inlined-absolute-print.html ├── index-inlined-absolute.html ├── index-inlined-async-final-print.html ├── index-inlined-async-final.html ├── index-inlined-async-integrity-print-default.html ├── index-inlined-async-integrity-print.html ├── index-inlined-async-integrity.html ├── index-inlined-async-minified-final-print.html ├── index-inlined-async-minified-final.html ├── index-inlined-print-default.html ├── index-inlined-print.html ├── index-inlined.html ├── index-loadcss.html ├── index-noscript-inlined-minified-final.html ├── index-nostyle.html ├── issue-300.html ├── loadcss-again.html ├── print.html ├── replace-stylesheets-body.html ├── replace-stylesheets-default-ignore.html ├── replace-stylesheets-default.html ├── replace-stylesheets-media.html ├── replace-stylesheets-polyfill.html ├── replace-stylesheets-swap.html ├── simple-critical-body.html ├── simple-critical-default.html ├── simple-critical-media.html ├── simple-critical-polyfill.html ├── simple-critical-swap.html └── test-svg.html ├── fixtures ├── bower_components │ └── bootstrap │ │ ├── .bower.json │ │ └── dist │ │ └── css │ │ └── bootstrap.css ├── cartoon-absolute.html ├── cartoon.html ├── critical.css ├── css │ ├── cartoon.css │ ├── main.css │ └── simple.css ├── entities.html ├── entities2.html ├── external.html ├── index-absolute.html ├── index-inlined.html ├── index-integrity.html ├── index-noscript.html ├── index-nostyle.html ├── index.html ├── issue-300.html ├── loadcss-again.html ├── loadcss.html ├── print.html ├── replace-stylesheets.html ├── simple.html └── svg.html ├── helper └── index.js └── index.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [package.json] 12 | indent_style = space 13 | indent_size = 2 14 | 15 | [*.yml] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - "!dependabot/**" 8 | pull_request: 9 | branches: 10 | - main 11 | - "!dependabot/**" 12 | schedule: 13 | - cron: "0 0 * * 0" 14 | workflow_dispatch: 15 | 16 | jobs: 17 | analyze: 18 | name: Analyze 19 | runs-on: ubuntu-latest 20 | permissions: 21 | actions: read 22 | contents: read 23 | security-events: write 24 | 25 | steps: 26 | - name: Clone repository 27 | uses: actions/checkout@v4 28 | with: 29 | persist-credentials: false 30 | 31 | - name: Initialize CodeQL 32 | uses: github/codeql-action/init@v3 33 | with: 34 | languages: "javascript" 35 | queries: +security-and-quality 36 | 37 | - name: Autobuild 38 | uses: github/codeql-action/autobuild@v3 39 | 40 | - name: Perform CodeQL Analysis 41 | uses: github/codeql-action/analyze@v3 42 | with: 43 | category: "/language:javascript" 44 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - "!dependabot/**" 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | env: 12 | FORCE_COLOR: 2 13 | NODE: 20 # The Node.js version to run lint on 14 | 15 | jobs: 16 | run: 17 | name: Lint 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - name: Clone repository 22 | uses: actions/checkout@v4 23 | with: 24 | persist-credentials: false 25 | 26 | - name: Set up Node.js 27 | uses: actions/setup-node@v4 28 | with: 29 | node-version: ${{ env.NODE }} 30 | cache: npm 31 | 32 | - name: Install npm dependencies 33 | run: npm ci 34 | 35 | - name: Run lint 36 | run: npm run lint 37 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - "!dependabot/**" 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | env: 12 | FORCE_COLOR: 2 13 | NODE_COV: 20 # The Node.js version to run coveralls on 14 | 15 | jobs: 16 | test: 17 | name: Node ${{ matrix.node }} on ${{ matrix.os }} 18 | runs-on: ${{ matrix.os }} 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | node: [18, 20] 24 | os: [ubuntu-latest, windows-latest] 25 | 26 | steps: 27 | - name: Clone repository 28 | uses: actions/checkout@v4 29 | with: 30 | persist-credentials: false 31 | 32 | - name: Set up Node.js 33 | uses: actions/setup-node@v4 34 | with: 35 | node-version: ${{ matrix.node }} 36 | architecture: ${{ matrix.architecture }} 37 | cache: npm 38 | 39 | - name: Install npm dependencies 40 | run: npm ci 41 | 42 | - name: Run tests 43 | run: npm run jest 44 | 45 | - name: Run Coveralls 46 | uses: coverallsapp/github-action@v2 47 | if: startsWith(matrix.os, 'ubuntu') && matrix.node == env.NODE_COV 48 | with: 49 | github-token: "${{ secrets.GITHUB_TOKEN }}" 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .DS_Store 3 | node_modules/ 4 | npm-debug.log 5 | test/fixtures/css/cartoon.18d89c7f.css 6 | test/fixtures/css/main.158f2990.css 7 | test/fixtures/bower_components/bootstrap/dist/css/bootstrap.0151e5ef.css 8 | test/fixtures/css/cartoon.64faf7bc.css 9 | 10 | .nyc_output 11 | coverage 12 | 13 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | lockfile-version=2 2 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | v5.2.1 / 2019-06-13 3 | =================== 4 | 5 | * Test node 12 6 | * Bump dependencies 7 | 8 | v5.2.0 / 2019-03-26 9 | =================== 10 | 11 | * Allow to configure noscript position 12 | 13 | v5.1.3 / 2019-01-16 14 | =================== 15 | 16 | * fix: removed endless loop in getPartials 17 | 18 | v5.1.2 / 2019-01-08 19 | =================== 20 | 21 | * fix: remove stylesheets on empty replace array 22 | 23 | v5.1.1 / 2019-01-02 24 | =================== 25 | 26 | * fix: prevent newline in case of 0 noscripts 27 | 28 | v5.1.0 / 2019-01-02 29 | =================== 30 | 31 | * feature: move noscript links to end of document #139 32 | 33 | v5.0.1 / 2019-01-01 34 | =================== 35 | 36 | * Tweaked package.json 37 | 38 | v5.0.0 / 2018-12-30 39 | =================== 40 | 41 | * Switched to jsdom (#240) 42 | * Bump dependencies 43 | * fix: prevent multiple loadcss includes 44 | * feature: compare/check already inlined styles 45 | * feature: drop cave in favour of postcss-discard 46 | * Move tests to Jest 47 | * Change indentation to 2 spaces 48 | * drop node 6 support 49 | 50 | v4.0.7 / 2018-11-29 51 | =================== 52 | 53 | * Add temporary fix for breaking svgs 54 | * Bump dependencies 55 | 56 | v4.0.6 / 2018-11-28 57 | =================== 58 | 59 | * Add another SVG Test 60 | 61 | v4.0.5 / 2018-09-15 62 | =================== 63 | 64 | * fix: consider ignore passed as string 65 | * Bump dependencies 66 | 67 | v4.0.4 / 2018-06-13 68 | ================== 69 | 70 | * Bump dependencies 71 | 72 | v4.0.3 / 2018-04-18 73 | ================== 74 | 75 | * Test existance of extracted stylesheets 76 | * Support minifying extracted css (#237) 77 | 78 | v4.0.2 / 2018-03-21 79 | =================== 80 | 81 | * Remove type attribute (#236) 82 | 83 | v4.0.1 / 2018-03-18 84 | ================== 85 | 86 | * Fixes inlining if no scripts & stylesheets are present in head 87 | 88 | v4.0.0 / 2018-03-05 89 | =================== 90 | 91 | * drop node 4 support 92 | * Bump deps 93 | * Fixes minor typos in README.md (#233) 94 | 95 | v3.1.0 / 2017-12-15 96 | =================== 97 | 98 | * Fix outdated yarn.lock 99 | * Bump dependencies 100 | * CI: stop testing non-LTS node.js versions. (#232) 101 | * Set the `onload` handler to `null`. (#231) 102 | 103 | v3.0.0 / 2017-11-29 104 | =================== 105 | 106 | * Upgrade loadCSS dep to 2.0.1 and update code and make it work with this version (#229) 107 | 108 | v2.4.2 / 2017-07-03 109 | ================== 110 | 111 | * Bump dependencies 112 | 113 | v2.4.1 / 2017-05-19 114 | =================== 115 | 116 | * Bump dependencies 117 | 118 | v2.4.0 / 2017-02-26 119 | =================== 120 | 121 | * Bump dependencies 122 | 123 | v2.3.0 / 2017-02-10 124 | =================== 125 | 126 | * Added some badges 127 | * Update travis 128 | * bump dependencies 129 | 130 | 2.2.0 / 2016-09-03 131 | ================== 132 | 133 | * add appveyor 134 | * Minimum node.js version is 4.0 now due to upstream changes. 135 | * Bump dependencies 136 | 137 | v2.1.5 / 2016-04-18 138 | =================== 139 | 140 | * fixed indent when using extract 141 | 142 | v2.1.4 / 2016-04-18 143 | =================== 144 | 145 | * minor regex fix 146 | 147 | v2.1.3 / 2016-04-18 148 | =================== 149 | 150 | * style tweaks 151 | * trim empty lines in non-minified css 152 | 153 | v2.1.2 / 2016-04-18 154 | =================== 155 | 156 | * republished with stable node version cause of missing files 157 | 158 | v2.1.1 / 2016-04-18 159 | =================== 160 | 161 | * correct process.exit on cli 162 | * handle buffer 163 | * added minify default 164 | * minor fixes 165 | 166 | v2.1.0 / 2016-04-17 167 | =================== 168 | 169 | * bump dependencies 170 | * minify defaults to true 171 | * gitignore tweaks 172 | * keep format & source order 173 | 174 | 2.0.0 / 2016-04-14 175 | ================== 176 | 177 | * Update to loadcss v1.2.0 + cssrelpreload 178 | * Bump dependencies 179 | 180 | 1.0.0 / 2015-11-13 181 | ================== 182 | 183 | * switched from jshint to xo 184 | * Bump deps 185 | * Use loadCSS from node_modules 186 | * Bump loadCSS 187 | 188 | 0.3.1 / 2015-07-10 189 | ================== 190 | 191 | * loadCSS Tweaks 192 | 193 | 0.3.0 / 2015-06-25 194 | ================== 195 | 196 | * Added CLI tests & bumped loadcss version 197 | * Added CLI 198 | 199 | 0.2.2 / 2015-06-10 200 | ================== 201 | 202 | * Fix #9 203 | 204 | 0.2.1 / 2015-06-09 205 | ================== 206 | 207 | * fixed tests 208 | * Update README.md 209 | 210 | 0.2.0 / 2015-06-09 211 | ================== 212 | 213 | * Ignore noscript-wrapped link tags 214 | * Added ignore option 215 | 216 | 0.1.4 / 2015-04-30 217 | ================== 218 | 219 | * Added test for #8 (skipped) 220 | * Don't encode entities 221 | * Removed failing quickfix related to #8 222 | * Better testcase for #8 223 | 224 | 0.1.3 / 2015-04-28 225 | ================== 226 | 227 | * Added fix for #8 228 | * bump deps 229 | 230 | 0.1.2 / 2015-03-30 231 | ================== 232 | 233 | * bump deps 234 | 235 | 0.1.1 / 2015-03-30 236 | ================== 237 | 238 | * bump deps 239 | 240 | 0.1.0 / 2015-02-23 241 | ================== 242 | 243 | * minor tweaks 244 | * fixed #6 245 | 246 | 0.0.10 / 2015-02-27 247 | ================== 248 | 249 | * fixes #7 250 | * travis tweaks 251 | 252 | 0.0.9 / 2014-12-08 253 | ================== 254 | 255 | * some cleanup 256 | * Use original loadCSS 257 | * moved loadcss in the head 258 | * Updated package.json 259 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Ben Zörb 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of Ben Zörb nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY BEN ZÖRB ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL BEN ZÖRB BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inline-critical 2 | 3 | Inline critical-path css and load the existing stylesheets asynchronously. 4 | Existing link tags will also be wrapped in `