Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55030 new defect (bug)

wp_enqueue_script( 'jquery-ui-autocomplete' ) - is enqueueing a bunch of extra scripts I don't need

Reported by: wpfed's profile wpfed Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Script Loader Keywords:
Focuses: javascript Cc:

Description

When I enqueue default scripts located in WP, specifically

<?php
wp_enqueue_script( 'jquery-ui-autocomplete' )

All of these extra scripts are also loaded on the front-end:

wp-includes/js/dist/a11y.min.js
wp-includes/js/dist/i18n.min.js
wp-includes/js/dist/hooks.min.js
wp-includes/js/dist/dom-ready.min.js
wp-includes/js/dist/vendor/wp-polyfill.min.js
wp-includes/js/dist/vendor/regenerator-runtime.min.js

I was using this reference:
https://developer.wordpress.org/reference/functions/wp_enqueue_script/#default-scripts-and-js-libraries-included-and-registered-by-wordpress

Is this normal behavior?

Change History (3)

#1 @peterwilsoncc
2 years ago

  • Component changed from General to Script Loader
  • Focuses javascript added

#2 @wpfed
2 years ago

I discovered that two of the extra scripts are coming from contact form 7, it adds dependency for wp-polyfill which has a dependency on regenerator.

wp-includes/js/dist/vendor/wp-polyfill.min.js
wp-includes/js/dist/vendor/regenerator-runtime.min.js

Looks like the core adds extra dependencies as well:

$scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.12.1', 1 );

Looks like best practice is to not use WP packages as they add many unnecessary scripts. Unfortunately plugin authors use them sometimes which is going to slow down many sites.

This can be closed.

Note: See TracTickets for help on using tickets.