rt-optimizer icon indicating copy to clipboard operation
rt-optimizer copied to clipboard

Add plugin options to load scripts on main or worker thread

Open pradeep910 opened this issue 4 years ago • 0 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.

Screenshot 2021-11-12 at 1 24 50 PM

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

pradeep910 avatar Nov 12 '21 07:11 pradeep910