2017 © Pedro Peláez
 

wordpress-plugin minit

A WordPress plugin to combine CSS and Javascript files

image

kasparsd/minit

A WordPress plugin to combine CSS and Javascript files

  • Tuesday, March 14, 2017
  • by kasparsd
  • Repository
  • 28 Watchers
  • 276 Stars
  • 131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 55 Forks
  • 23 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

Minit for WordPress

Places all your CSS and Javascript files into dedicated bundles that can be cached by browsers and re-used between requests. It assumes that a single request with slightly larger transfer size is more performant than multiple smaller requests (even with HTTP/2 multiplexing)., (*1)

Install

Install using Composer:, (*2)

composer require kasparsd/minit

or by manually downloading the latest release file., (*3)

How it Works

  • Concatenates all CSS files and Javascript files one file for each type (.js and .css), and stores them in the WordPress uploads directory under /minit. See the configuration section below for how to exclude files from the bundle., (*4)

  • Uses the combined version numbers of the enqueued assets to version the bundles., (*5)

  • Loads the concatenated Javascript file asynchronously in the footer. This will probably break all inline scripts that rely on jQuery being available. See the configuration section below for how to disable this., (*6)

Screenshots

  1. All CSS files combined in a single file
  2. All external Javascript files loading asynchronously

Configuration

See the Wiki for additional documentation., (*7)

Disable Asynchronous Javascript

Use the minit-script-tag-async filter to load the concatenated Javascript synchronously:, (*8)

add_filter( 'minit-script-tag-async', '__return_false' );

Exclude Files

Use the minit-exclude-js and minit-exclude-css filters to exclude files from the concatenated bundles:, (*9)

add_filter( 'minit-exclude-js', function( $handles ) {
    $handles[] = 'jquery';

    return $handles;
} );

Integrate with Block Themes

Full block-based themes enqueue the individual stylesheets only for the blocks that are required for the current request. This leads to bundles being unique between requests thus defeating the purpose or cache re-use. Use the should_load_separate_core_block_assets filter to enqueue a single block-library stylesheet instead on all requests:, (*10)

add_action(
    'plugins_loaded',
    function () {
        if ( class_exists( 'Minit_Plugin' ) ) {
            // Add late to override the default behaviour.
            add_filter( 'should_load_separate_core_block_assets', '__return_false', 20 );
        }
    },
    100 // Do it after all plugins are loaded.
);

Minify CSS

Use this filter to apply basic CSS minification to the created bundle:, (*11)

add_filter(
    'minit-content-css',
    function ( $css ) {
            $css = preg_replace( '/[\n\r\t]/mi', ' ', $css ); // Line breaks to spaces.
            $css = preg_replace( '/\s+/mi', ' ', $css ); // Multiple spaces to single spaces.

            return $css;
    },
    5 // Do it before the debug comment in the head.
);

Minit Addons

Credits

Created by Kaspars Dambis and contributors., (*12)

The Versions

14/03 2017

dev-fix/exclude-conditionals

dev-fix/exclude-conditionals https://github.com/kasparsd/minit

A WordPress plugin to combine CSS and Javascript files

  Sources   Download

GPLv2 or later

The Requires

 

wordpress css plugins js performance minify combine concatenate optimization speed

04/12 2016

dev-master

9999999-dev https://github.com/kasparsd/minit

A WordPress plugin to combine CSS and Javascript files

  Sources   Download

GPLv2 or later

The Requires

 

wordpress css plugins js performance minify combine concatenate optimization speed