Optimizing script loading, implementation

The “first run” of the script loading optimization is in trunktrunk A directory in Subversion containing the latest development code in preparation for the next major release cycle. If you are running "trunk", then you are on the latest revision.. It uses both methods: splits the scripts queue in head and footer parts, then concatenates and compresses them before sending them to the browser. Most CSSCSS Cascading Style Sheets. is also concatenated and compressed.

There are two new constants that disable concatenating and compression: CONCATENATE_SCRIPTS and COMPRESS_SCRIPTS. Setting the first to false would disable both concatenating and compression, the second disables compression only. There is also a simple AJAX method to test if compressing from PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 works as expected on the server. It is run only once and the result is saved as an option. It will run again if that option is deleted.

For pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party authors there are two new actions in the adminadmin (and super admin) footer: do_action('admin_print_footer_scripts'); and do_action("admin_footer-$hook_suffix");. The order of execution is:

  1. "admin_footer" can be used to print scripts before the default footer scripts
  2. "admin_print_footer_scripts" used to print the default scripts followed by any external scripts that were queued for the footer
  3. "admin_footer-$hook_suffix" can be used to print scripts that should appear on a specific admin page only

The preferable way for plugins to add scripts to admin pages would be either to enqueue them properly (which is a must if the script depends on a default script) or to use the $hook_suffix hooksHooks In WordPress theme and development, hooks are functions that can be applied to an action or a Filter in WordPress. Actions are functions performed when a certain event occurs in WordPress. Filters allow you to modify certain functions. Arguments used to hook both filters and actions look the same. to add them only where needed.

New hook(s) may also be needed in the functions dealing with splitting or concatenating the script queue. Suggestions are welcome either here as comments or on tracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. as enhancements tickets.

Update: added do_action('admin_enqueue_scripts', $hook_suffix); allowing plugins to easily queue scripts on the exact pages. To find out the value for $hook_suffix on a specific page, echo it from your function and visit the page.

Queueing a script for the footer follows the same syntax as in script loader:

$scripts->add( 'handle', 'full/url/to/file.js', array( 'dependency' ), 'version' );
$scripts->add_data( 'handle', 'group', 1 );

Group 1 means queue for the footer, group 0 (zero) is the default.

#optimization