Requirejs for Php in Wordpress Theme Development

Often we saw so many javascript file used in plugins and themes that we installed. Thinking about that, i come up with this idea to solve these;

  1. avoid redundant load javascript
  2. load specific javascript after those required modules are ready

For example, I going to develop a child-theme. I want to use `Vue`, `VueCarousel` and  `jQuery.fn.modal` for my custom gallery that i build in the `/template-parts/content-product_gallery.js` which is the template block main script. 

So, with this `requirejs` function. I can serve those module right from my template if those dependencies not available.

In the future, i might need to upgrade it to also help check the module version to make sure it really compatible. But for now, let's keep it simple stupid like that first.

This function included in my StrongBase theme. Let's give a try ``.


Popular Posts