Question

Im using Play! 1.2.5 and Greenscript 1.2.8b. Im looking to have a fallback for jQuery and other javascript library if one the CDN is not responding.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="@{'public/javascripts/jquery-1.7.2.min.js'}">\x3C/script>')</script>

This works fine but is there a way to do this with Greenscript?

I have tried to do the same thing with greenscript, but other scripts that depends on jQuery loads at the same time and will break the site:

#{greenscript.js 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' } window.jQuery || document.write('<script src="@{'public/javascripts/jquery-1.7.2.min.js'}">\x3C/script>') #{/greenscript.js}

It would be great to have something like this:

js.default=https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js || jquery-1.7.2.min

Was it helpful?

Solution

Your requirement is unlikely to be implemented as greenscript shall not test the network connectivity when parsing the tag, because it might very well happen that at precompile time the internet is not available.

I'd recommend you to use the <script> tag rather than greenscript to load jquery for your case.

BTW, 1.2.8b is an outdated version. Because playframework doesn't accept module update, you should follow https://gist.github.com/greenlaw110/2868365 to update your greenscript version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top