Use requirejs modules to localize scripts instead of global variables
-
Hi, i’m refactoring the javascript of my plugin to use requirejs.
This will allow me to avoid exposing any global javascript variable, and i will be able to include my version of the libraries so that i will not depend on wordpress version anymore (yes, there is a little overhead, but in this way i’m sure that my plugin will work exactly the same on each wordpress version). The only global variables i’m using are those created by wp_localize_script(), and that’ something i would like to get rid of.So i would like to create a new function wp_localize_script_define() which, instead of creating a global variable, creates a module. something like
<script type="text/javascript"> define( "my/module", { property : value } ); </script>
that seems to be possible because after all wp_localize_script() uses function of the globally available
$wp_scripts
class, the only thing that would be very welcome would be the ability to add the script AFTER and not before another script, is there a way to do this?But things could work even without that, apart from that do you spot any potential problem?
- The topic ‘Use requirejs modules to localize scripts instead of global variables’ is closed to new replies.