I'm using requirejs in a wordpress plugin. I'm trying to use it so that only the javascript needed for the page is loaded. My idea is to have a main.js file that loads the js for the current page, but i was wondering how to tell main.js what file to load.
require(
[ "pages/name-of-the-page" ], // How do i tell require that we are on page x?
function( page ) {
page.start();
}
);
I was thinking about what to use, maybe i should set a cookie server-side, read it and then use that data?Use the url parameters to guess the page?What should i do?