Skip to content

Commit

Permalink
For CSS the order is important (#118)
Browse files Browse the repository at this point in the history
Adding all after styles after the bundle breaks the order of styles so we keep them in the bundle instead.
  • Loading branch information
kasparsd committed Feb 23, 2024
1 parent b4b35df commit b05d417
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion minit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://github.com/kasparsd/minit
GitHub URI: https://github.com/kasparsd/minit
Description: Combine JS and CSS files and serve them from the uploads folder.
Version: 1.4.1
Version: 1.5.0
Author: Kaspars Dambis
Author URI: https://kaspars.net
*/
Expand Down
5 changes: 4 additions & 1 deletion src/minit-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function register( $todo ) {
/**
* Get a cache key for a set of assets for the current request.
*
* TODO: Account for before and after values being included
* in the bundle in case of CSS.
*
* @param array $handles List of asset handle strings.
*
* @return string
Expand All @@ -61,7 +64,7 @@ public function cache_key( $handles = array() ) {
'minit_cache_ver-' . $this->file_cache()->version(), // Use a global cache version key to purge cache.
);

// Include individual scripts versions in the cache key
// Include individual scripts versions in the cache key.
foreach ( $handles as $handle ) {
$ver[] = sprintf( '%s-%s', $handle, $this->handler->registered[ $handle ]->ver );
}
Expand Down
20 changes: 7 additions & 13 deletions src/minit-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,17 @@ public function process( $todo ) {
// Add our Minit style since wp_enqueue_script won't do it at this point
$todo[] = self::ASSET_HANDLE;

// Add inline styles for all minited styles
foreach ( $this->done as $script ) {
// Can this return an array instead?
$inline_styles = $this->handler->get_data( $script, 'after' );

if ( ! empty( $inline_styles ) ) {
$this->handler->add_inline_style(
self::ASSET_HANDLE,
implode( "\n", $inline_styles )
);
}
}

return $todo;
}

public function minit_item( $content, $handle, $src ) {
// Append all inline styles right after to preserve order.
$inline_styles = $this->handler->get_data( $handle, 'after' );

if ( ! empty( $inline_styles ) ) {
$content .= implode( "\n", $inline_styles );
}

if ( empty( $content ) ) {
return $content;
}
Expand Down

0 comments on commit b05d417

Please sign in to comment.