javascriptfrontendsitemesh

How to define JavaScript at the and of the page (because of performance issues) with SiteMesh3?


I'm using SiteMesh3 in my project but I don't know how to solve this problems: For performance issues, I want to put my specific JavaScripts at the end of my pages (http://developer.yahoo.com/performance/rules.html#js_bottom) and the generic ones, such JQuery import, at the end of my decorator.

The problem is that when I inject my specific JS into decorator, JQuery wasn't imported yet and the page doesn't work.

I've tried to put my content into , but SiteMesh doesn't recognize it, just .

Is there a way to solve this without import JQuery into each page an keeping it at the end of my decorator?

Thanks a lot for the attention.


Solution

  • I found this solution:

    Add this tags into sitemesh3.xml:

    <content-processor>
        <tag-rule-bundle class="org.sitemesh.content.tagrules.html.DivExtractingTagRuleBundle" />
    </content-processor>
    

    Then add a div with a specific name into your HTML. Example:

    <div id="siteMeshJavaScript">
        <script type="text/javascript">
            ...
        </script>
    </div>
    

    Finally, add a reference to this div inside decorator wherever you want to:

    <sitemesh:write property='div.siteMeshJavaScript'/>