I'm working on a site which, though not enormous, has enough JavaScript to make me feel that it'd benefit from requirejs. The modular way that we break the page up (and functionality) seems to support this too.
While there's plenty of examples of using requirejs in single page applications, I can't see many examples of use on a non-SPA site.
For example, I'm using jQuery UI Tabs, which I want to be run on every page. So I'd want to run something like $('.tabs').tabs();
Would you just put this in your main.js/app.js
(or whatever you specify for data-main
)?
Second question. The page is built up using HTML/CSS modules. The CMS behind the site knows which HTML/CSS modules are on the page and so I can dynamically write the requirejs config so that I know which JavaScript modules to initialise. Is this a common approach? Although I may actually include all JavaScript files, I'm keen to optimise the code in main.js
to ensure that it's only executing code for modules that are being used on the page. Has anyone done this?
Thanks very much,
James.