Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
913a27b
Inline styles if size is smaller than a threshold
aristath Jan 20, 2021
434b7c6
Add a global pool to avoid too many inline styles
aristath Jan 20, 2021
fcd9389
Merge branch 'master' into try/sustainable-styles
aristath Jan 21, 2021
c207726
change default max pool size to 20k
aristath Jan 22, 2021
137b7cf
Add the original block-name as a param in filters
aristath Jan 22, 2021
2de9db9
Refactor the should-inline calculations
aristath Jan 22, 2021
f734c09
Merge branch 'master' into try/sustainable-styles
aristath Jan 22, 2021
04f05a8
Merge branch 'master' into try/sustainable-styles
aristath Jan 25, 2021
a99f443
Merge branch 'master' into try/sustainable-styles
aristath Jan 25, 2021
0a079f0
Use a transient to cache file sizes
aristath Jan 25, 2021
c7d3dea
Cleanup
aristath Jan 25, 2021
b35e6e7
make sure size is an integer
aristath Jan 25, 2021
c8f22c2
Change threshold to 1500
aristath Jan 25, 2021
6af3170
Remove the total size checks
aristath Jan 25, 2021
60a0be0
Merge branch 'master' into try/sustainable-styles
aristath Feb 1, 2021
4d10158
Merge branch 'master' into try/sustainable-styles
aristath Feb 1, 2021
d22202c
Merge branch 'master' into try/sustainable-styles
aristath Feb 2, 2021
b0ad350
Completely refactor the implementation
aristath Feb 2, 2021
6536df8
Merge branch 'master' into try/sustainable-styles
aristath Feb 2, 2021
253f273
Break the loop when appropriate
aristath Feb 2, 2021
a71ca1f
changed limit to 20k
aristath Feb 2, 2021
ed35fa8
simplify
aristath Feb 2, 2021
bedf8e1
Merge branch 'master' into try/sustainable-styles
aristath Feb 2, 2021
8f681d0
Merge branch 'master' into try/sustainable-styles
aristath Feb 3, 2021
016462e
more tweaks
aristath Feb 3, 2021
74e25fa
Merge branch 'master' into try/sustainable-styles
aristath Feb 4, 2021
1219cae
Use wp_style_add_data, props @gziolo
aristath Feb 4, 2021
d222b39
Simplify condition - props @gziolo
aristath Feb 4, 2021
c493c9a
Add file_exists check back
aristath Feb 4, 2021
bcc0c15
simplify sorting function
aristath Feb 5, 2021
af53a2e
rename var from $stylesheet to $style
aristath Feb 5, 2021
22045e8
typecasting not needed here
aristath Feb 5, 2021
f3f0705
Merge branch 'master' into try/sustainable-styles
aristath Feb 5, 2021
be984b7
rename functions
aristath Feb 5, 2021
c9caa4f
Add basic phpunit tests for the minify function
aristath Feb 5, 2021
91055b4
Merge branch 'master' into try/sustainable-styles
aristath Feb 9, 2021
ba2ef33
Merge branch 'master' into try/sustainable-styles
aristath Feb 11, 2021
ef9216a
Merge branch 'master' into try/sustainable-styles
aristath Feb 12, 2021
fb90254
Merge branch 'master' into try/sustainable-styles
aristath Feb 16, 2021
dba0939
Allow inlining the common.css file if possible
aristath Feb 16, 2021
836e489
improve inline doc
aristath Feb 17, 2021
79b2635
inline docs tweak
aristath Feb 17, 2021
68d9956
Merge branch 'master' into try/sustainable-styles
aristath Feb 17, 2021
716031c
Add wp_style_add_data in docs example
aristath Feb 17, 2021
9309de8
docs
aristath Feb 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Break the loop when appropriate
  • Loading branch information
aristath committed Feb 2, 2021
commit 253f273d2e13da652592824138367b490c405a21
34 changes: 18 additions & 16 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,26 +268,28 @@ function( $a, $b ) {
// Loop styles.
foreach ( $styles as $stylesheet ) {

// Make sure that adding this style won't go over the maximum defined value.
if ( $total_inline_size + $stylesheet['size'] < $total_inline_limit ) {
// Size check.
if ( $total_inline_size + $stylesheet['size'] > $total_inline_limit ) {
// Exit the loop, all subsequent stylesheets will be larger since we previously ordered them by size.
break;
}

// Get the styles.
$stylesheet_contents = false === $stylesheet['css'] || null === $stylesheet['css']
? file_get_contents( $stylesheet['path'] )
: $stylesheet['css'];
// Get the styles.
$stylesheet_contents = false === $stylesheet['css'] || null === $stylesheet['css']
? file_get_contents( $stylesheet['path'] )
: $stylesheet['css'];

// Make sure that "after" is defined in order to add inline styles.
if ( ! isset( $wp_styles->registered[ $stylesheet['handle'] ]->extra['after'] ) ) {
$wp_styles->registered[ $stylesheet['handle'] ]->extra['after'] = array();
}
// Make sure that "after" is defined in order to add inline styles.
if ( ! isset( $wp_styles->registered[ $stylesheet['handle'] ]->extra['after'] ) ) {
$wp_styles->registered[ $stylesheet['handle'] ]->extra['after'] = array();
}

// Set `src` to `false` and add styles inline.
$wp_styles->registered[ $stylesheet['handle'] ]->src = false;
$wp_styles->registered[ $stylesheet['handle'] ]->extra['after'][] = $stylesheet_contents;
// Set `src` to `false` and add styles inline.
$wp_styles->registered[ $stylesheet['handle'] ]->src = false;
$wp_styles->registered[ $stylesheet['handle'] ]->extra['after'][] = $stylesheet_contents;

// Add the styles size to the $total_inline_size var.
$total_inline_size += (int) $stylesheet['size'];
}
// Add the styles size to the $total_inline_size var.
$total_inline_size += (int) $stylesheet['size'];
}
}
}
Expand Down