I would like to load in page-specific Javascripts that have dependencies. I know about: @scripts as described in the documentation
But I'd like to use Require.js to manage my module dependencies :
require([
'jquery',
'bootstrap',
'unicorn'
], function($){
//console.log(document.location.pathname); // causes integration test to fail
switch (document.location.pathname)
{
case '/login' :
require(['lib/login'], function(){
// maybe some validation
})
case '/events' :
require (['lib/underscore']), function () {
// page-specific scripts
})
}
Is there a better way to handle page-specific scripts. For example if I have:
case 'events/:id'
It's not the best idea to be doing regular expression matching. I'd much rather have it in server-side templates. Should I use something like Backbone.js router. If so, how do it do it?
Also, I cannot just include a tag into my server-side templates because I inherit the require.js and data-main from my main.scala.html
@helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("js/main").url)
Thanks! Jack Chi