New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@elderjs/plugin-critical-path-css

Package Overview
Dependencies
Maintainers
2
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elderjs/plugin-critical-path-css

Easily generate critical path css for your Elder.js powered website.

  • 1.8.0-beta.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Elder.js Plugin: Critical Path CSS

Easily generate critical path css for your Elder.js websites using critical.

While Svelte does a great job of scoping CSS usually you'll have a site wide css file to hold common styles.

If you're using a common css file and are optimizing for load speed, you'll want to defer the common css file and include critical path css.

This plugin generates the critical path css for each of your templates and automatically includes it in the head when generating the page.

Further Reading: (If you're unfamiliar with why you'd want to use critical path css, we suggest you do some googling on "Critical Path CSS", "FOUC", "Cumulative Layout Shift", and "Lighthouse Audit.")

Install

npm install --save @elderjs/plugin-critical-path-css

Config

Once installed, open your elder.config.js and configure the plugin by adding @elderjs/plugin-critical-path-css to your plugin object.

plugins: {

  '@elderjs/plugin-critical-path-css': {
    rebuild: false, // set to true to rebuild the critical path css on next build. NOTE: completely overwrites allRequests.
    folder: `./src/assets/critical/`, // relative to root of the project.
    requests: false, // used to specify the specific requests you want used for critical path css generation.
    disable: false, // if for some reason you don't want the critical path css added when the file exists. Also disables building.
    critical: { // settings here: https://github.com/addyosmani/critical
      penthouse: {
        forceInclude: [], // you can force include styles here '.btn' for example
        keepLargerMediaQueries: true,
      },
      dimensions: [
        {
          height: 500,
          width: 300,
        },
        {
          height: 900,
          width: 1280,
        },
      ],
    },
  },


}

Generating Critical Path CSS For Specific Pages On a Route

By default the plugin selects the first 'request' it finds that matches a route to generate critical path css for.

If you want more control or want to generate critical path css from multiple pages you can specify a requests object by route and you are able to control the exact requests the system will build with.

If you pass an array, the css from multiple pages is deduplicated and compressed.

plugins: {
  '@elderjs/plugin-critical-path-css': {
    requests: { // used to specify the specific requests you want used for critical path css generation.
      home: [{slug:'/'}],
      blog: [{slug: 'my-first-blog'}, {slug: 'elderjs-rocks'}]
    },
    cssFile: ['./src/assets/style.css'], // location of your website's css file. also accepts an array of files.
    rebuild: false, // set to true to rebuild the critical path css on next build. NOTE: completely overwrites allRequests.
    folder: `./src/assets/critical/`, // relative to root of the project.
    disable: false, // if for some reason you don't want the critical path css added when the file exists. Also disables building.
    critical: { // settings here: https://github.com/addyosmani/critical
      penthouse: {
        forceInclude: [], // you can force include styles here '.btn' for example
        keepLargerMediaQueries: true,
      },
      dimensions: [
        {
          height: 500,
          width: 300,
        },
        {
          height: 900,
          width: 1280,
        },
      ],
    },
  },
}

You probably don't want to tinker with your elder.config.js file each time you want to rebuild so this plugin accepts the ELDER_REBUILD_CRITICAL_PATH env variable.

If that is the case, update your package.json file to include the following script:

"build:critical": "ELDER_REBUILD_CRITICAL_PATH=true node ./src/build",

Then you can run it using npm run build:critical.

Note: this assumes your build file is at ./src/build so update the script accordingly.

Keywords

FAQs

Package last updated on 15 Jul 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc