Help Appreciated | Need Code to Dequeue and Deregister JS Files On Mobile
-
Good Day,
We have partially covered this topic here and here.
After careful evaluation, once again, we need to ask you a favor. We need a code snippet that will help us dequeue and deregister your “dynamic” JS files (e.g.,
/jc.js
and/base.js
) on mobile devices and tablets for your new plugin version, V3.+Based on one of your previous comments, we don’t see a need for the dynamic JS files (nor corresponding dynamic data-handles) since the odds for a website to have more than one language selector on one page is practically nil.
So, in short, it would be awesome if you can update your plugin’s code to help with this request. Yours is the only plugin that we know of that uses dynamic JS files (i.e., data-handles). Heck, it didn’t before V3.+!
If you can change them to them to static, we can easily dequeue and deregister your JS files with the PHP code snippet provided below, which we already use for other plugins.
add_action( 'wp_print_scripts', 'dequeue_unnecessary_scripts' ); function dequeue_unnecessary_scripts() { if(window.innerWidth < 760) { wp_dequeue_script( 'js-data-handle-1' ); wp_deregister_script( 'js-data-handle-1' ); wp_dequeue_script( 'js-data-handle-2' ); wp_deregister_script( 'js-data-handle-2' ); } }
As you know, every bit of payload saved helps improve website performance.
Here’s a great corollary:
"Even the greatest ships can sink one leak at a time." -- Thomas A. Edison.
Thanks for reading. Thanks for your help!
- The topic ‘Help Appreciated | Need Code to Dequeue and Deregister JS Files On Mobile’ is closed to new replies.