2017 © Pedro Peláez
 

library wp-async-defer-scripts

image

wpscholar/wp-async-defer-scripts

  • Monday, November 6, 2017
  • by wpscholar
  • Repository
  • 1 Watchers
  • 2 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 200 % Grown

The README.md

WordPress Async/Defer Scripts

A Composer library for asynchronously loading or deferring scripts in WordPress., (*1)

Requirements

  • PHP 5.3+
  • WordPress 4.2+

Installation

Add the module to your code base via Composer, (*2)

composer require wpscholar/wp-async-defer-scripts

Be sure to require the Composer autoloader in your project, (*3)

<?php

require __DIR__ . '/vendor/autoload.php';

Usage

How to asynchronously load a script:, (*4)

<?php

add_action( 'wp_enqueue_scripts', function () {
    wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js' );
    wp_scripts()->add_data( 'recaptcha', 'async', true );
} );

How to defer loading of a script:, (*5)

<?php

add_action( 'wp_enqueue_scripts', function () {
    wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js' );
    wp_scripts()->add_data( 'recaptcha', 'defer', true );
} );

Initialization

In most cases, you can simply follow the installation instructions and things will just work. However, if you are including this library outside of a WordPress plugin or theme, you may have to manually initialize the class:, (*6)

<?php

wpscholar\WordPress\AsyncDeferScripts::initialize();

The Versions

06/11 2017

dev-master

9999999-dev

  Sources   Download

GPL-2.0+

06/11 2017

1.1

1.1.0.0

  Sources   Download

GPL-2.0+

08/09 2017

1.0

1.0.0.0

  Sources   Download

GPL-2.0+