Add plugin options for better scripts loading
Closed this issue · 1 comments
Issue
Some scripts have dependencies on other scripts. So if core script is not loaded for example jquery
, then it causes Javascript error and breaks functionality.
Possible solutions to try
One way would be to check scripts dependencies We can check the scripts with $deps
argument and load those dependencies normally with type="text/javascript"
.
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer);
However, there will be some scripts which don't define dependencies, there will be JS error in this case.
The other way is to provide options on backend to allow users to skip or include JS files. Something like an input field with comma separated script names like wp-autoptimize plugin does.
The comma separated JS file names, can be added to $skip_js
variable here - https://github.com/rtCamp/rt-scripts-optimizer/blob/main/rt-scripts-optimizer.php#L80-L85
Duplicate issue #6