Hi, I've been trying to get the tapestry5-portlet bridge up and running with the newest T5.4 previews, just to learn a little about the technologies.
Basically each portlet corresponds to a page, so I see a lot of duplicate javascript in the portal pages (a set of scripts per portlet). The loading of all these duplicated javascript files does not seem to suffer much, as they are cached. But the ModuleManagerImpl defines a page variable called "require". When "require" is defined multiple times; things break down (looks like a race condition where the variable enters un-initialized state here and there). The fix I came up with to ensure that "require" is only defined once (all occurrences seem to have same configuration) is: diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java b/tapestry-core/src/main/j index 26cb24c..9c540b5 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java @@ -100,7 +100,7 @@ public class ModuleManagerImpl implements ModuleManager } // This part gets written out before any libraries are loaded (including RequireJS). - return String.format("var require = %s;\n", config.toString(compactJSON)); + return String.format("if(typeof require == 'undefined'){var require = %s;}\n", config.toString(compactJSON)); } private JSONObject buildBaseConfig(Map<String, JavaScriptModuleConfiguration> configuration, boolean devMode) Also I'm seeing multiple class to "t5/core/pageinit.js" with different parameters, but it does not seem to break anything obvious. I'm not too familiar with requirejs, so does anyone have some ideas on how to be more clever when it comes to handling the many similar js files being requested? Also can anyone pitch in on the page initialization script being called multiple times with different params, will the portlet pages initialize successfully in all cases? Is it a viable strategy to attack things in the js layer? Or are there some tricks on the portlet container side of things that can be used to help the portlet bridge adjust tapestry to make better decisions about things like js includes? All input is appreciated ;-) -- Chris