7 Replies Latest reply on Aug 7, 2007 6:28 AM by snicoll

    What is the standard way to include Javascript resources acc

    snicoll

      Hello,

      We use a JS library in multiple portlets and we need to have it loaded at all times. Since we don't know which portlets will be deployed in which pages, we can't rely on the views content to define the Javascript.

      Currently we have hardcoded our script in:
      $JBOSS_PORTAL/server/default/deploy/jboss-portal.sar/portal-core.war/WEB-INF/jsp/header.jsp

      Is there a more portable way to do this?

        • 1. Re: What is the standard way to include Javascript resources

          Look at the documentation the jboss-portlet.xml declarative way to add your library to a portal page. The element name is header-content.

          • 2. Re: What is the standard way to include Javascript resources
            snicoll

             

            "julien@jboss.com" wrote:
            Look at the documentation the jboss-portlet.xml declarative way to add your library to a portal page. The element name is header-content.


            I know that!

            But If I have 4 portlets, I need this in all portlets and portlets can be set independently on the page. So what? I guess if I define this in the 4 portlets it will be loaded 4 times. The problem I have is that I should have only one declaration in the pagE.

            • 3. Re: What is the standard way to include Javascript resources

              So I think JBoss Portal at aggregation time should smartly aggregate the different headers in order to avoid to load the same resource several times.

              • 4. Re: What is the standard way to include Javascript resources
                snicoll

                 

                "julien@jboss.com" wrote:
                So I think JBoss Portal at aggregation time should smartly aggregate the different headers in order to avoid to load the same resource several times.



                Waouh, if it does that's kinda impressive :)

                • 5. Re: What is the standard way to include Javascript resources
                  snicoll

                   

                  "julien@jboss.com" wrote:
                  So I think JBoss Portal at aggregation time should smartly aggregate the different headers in order to avoid to load the same resource several times.



                  Jboss 2.6-CR2 does not. I have this (excerpt):

                  <portlet-app>
                   <portlet>
                   <portlet-name>DefaultMap</portlet-name>
                   <remotable>false</remotable>
                   <header-content>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=root"></script>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=tilapia&amp;roottreatment=asroot"></script>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=portlets-full&amp;roottreatment=asroot"></script>
                   </header-content>
                   </portlet>
                   <portlet>
                   <portlet-name>DefaultNavBar</portlet-name>
                   <remotable>false</remotable>
                   <header-content>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=root"></script>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=tilapia&amp;roottreatment=asroot"></script>
                   <script type="text/javascript"
                   src="/tilapa-portlets-base/resource?name=portlets-full&amp;roottreatment=asroot"></script>
                   </header-content>
                   </portlet>
                   [...]
                  </portlet-app>
                  


                  And I have X times the script definitions (where X is the number of portlets on the screen).

                  Too bad!

                  • 6. Re: What is the standard way to include Javascript resources

                    I used the word "should", I'll try to get something done by GA.

                    • 7. Re: What is the standard way to include Javascript resources
                      snicoll

                       

                      "julien@jboss.com" wrote:
                      I used the word "should", I'll try to get something done by GA.


                      Do I need to enter a Jira issue for this. I've tried GA and it's not implemented.

                      Thanks,
                      Stéphane