Replacing jQuery UI with lighter front-end plugin
-
Love this project! However, I’m not a big fan of jQuery UI, mainly because it needs 5 different JS files and a stylesheet to run.
On a recent project, I opted for the excellent and super light-weight jQuery Autocomplete plugin by DevBridge to replace jQuery UI.
Thought I’d share how, for any other performance-obsessed devs out there:
1) Disable this plugin’s front-end scripts by adding a line to your functions.php file:
add_filter('search_autocomplete_disable_frontscripts', '__return_true');
2) Download and enqueue the minified jQuery Autocomplete plugin.
3) Initiate autocomplete behavior with this bit of JS.
In the above gist, you must set
#s
to the CSS selector of your search input element, if different (this is the first option in the WP settings page for this plugin).The upside of this whole approach is that you save 6-7 files per page. The downside is that the following plugin options, which can be set in WP Dashboard, will no longer be passed to the front-end because we’ve disabled front-end scripts in step 1:
fieldName
minLength
delay
autoFocusBut these options can also easily be defined in step 3. Complete options for jQuery Autocomplete are documented here.
Hope this helps someone out there.
- The topic ‘Replacing jQuery UI with lighter front-end plugin’ is closed to new replies.