0

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.

Pmt
  • 1,122
  • 3
  • 13
  • 27

2 Answers2

2

Do not know if this solution is applicable to SiteMesh 3. I'm using SiteMesh 2. But I've the same problem you have. The solution I found was to surround the javascript with a tag "content" . And then in the decorator retrieve those values​​. For example: In the page to decorate:

<content tag="botton_javascript">
    <script>
        $(function() {
            console.log('This is a test');
        });
    </script>
</content>

In the decorator page:

<decorator:getProperty property="page.botton_javascript"></decorator:getProperty>

It's important to make use of tag attribute, you can order the import of javascript. In sitemesh 3, you've to replace decorator with sitemesh

Fernando.
  • 723
  • 8
  • 12
2

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'/>
Pmt
  • 1,122
  • 3
  • 13
  • 27