1

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

Jack Chi
  • 440
  • 4
  • 13

1 Answers1

0

+1 , I think that it's a real problem here, I'm working with angualrJs and I have almost the same problem with routers, The only thing I have succeeded to do is to handle this in the global controller class using notfoundError combined with regular expression [2ms] for every request.

I think play guys should work on this [may be it's implemented .... I don't know] I think the best idea is to do a virtual router as analogy to Apache virtual host.

Ben Rhouma Zied
  • 2,473
  • 3
  • 19
  • 29