Skip to content

Commit

Permalink
Critical CSS (#744)
Browse files Browse the repository at this point in the history
* Moves critical CSS to their own partials

* Adjusts entry points for main and critical files

* Updates webpack for multiple entry points

* Inlines the critical CSS file
  • Loading branch information
coreymcollins committed May 9, 2022
1 parent a3ea2cf commit 3131c07
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 8 deletions.
14 changes: 14 additions & 0 deletions inc/scripts.php
Expand Up @@ -32,6 +32,20 @@ function _s_scripts() {
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );

/**
* Inline Critical CSS.
*
* @author Corey Collins
*/
function _s_critical_css() {
?>
<style>
<?php include get_stylesheet_directory() . '/build/critical.css'; ?>
</style>
<?php
}
add_action( 'wp_head', '_s_critical_css', 1 );

/**
* Preload styles and scripts.
*
Expand Down
1 change: 1 addition & 0 deletions src/critical.js
@@ -0,0 +1 @@
import './scss/critical.scss';
5 changes: 0 additions & 5 deletions src/index.js
@@ -1,8 +1,3 @@
/* eslint eslint-comments/disable-enable-pair: error */
/* eslint-disable no-undef, no-unused-vars */

import './scss/tailwind.scss';
import './scss/index.scss';
import './js/index';

/* eslint-enable no-undef, no-unused-vars */
4 changes: 4 additions & 0 deletions src/scss/critical.scss
@@ -0,0 +1,4 @@
//----------------------------------------
// Critical CSS.
//----------------------------------------
@import 'critical/index.scss';
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions src/scss/critical/index.scss
@@ -0,0 +1,9 @@
//----------------------------------------
// Critical CSS
//
// Import partials for "above the fold" (barf) styles.
//----------------------------------------

@import 'header';
@import 'menus';
@import 'mobile-menus';
2 changes: 0 additions & 2 deletions src/scss/template-tags/index.scss
Expand Up @@ -5,8 +5,6 @@
//----------------------------------------

@import 'forms';
@import 'menus';
@import 'mobile-menus';
@import 'modals';
@import 'off-canvas';
@import 'svg-sprite-wrapper';
1 change: 0 additions & 1 deletion src/scss/templates/index.scss
Expand Up @@ -7,5 +7,4 @@

@import 'comments';
@import 'footer';
@import 'header';
@import 'posts';
4 changes: 4 additions & 0 deletions webpack.config.js
Expand Up @@ -14,6 +14,10 @@ const StylelintPlugin = require( 'stylelint-webpack-plugin' );
*/
module.exports = {
...defaultConfig,
entry: {
index: './src/index.js',
critical: './src/critical.js',
},
module: {
rules: [
{
Expand Down

0 comments on commit 3131c07

Please sign in to comment.