Partial Caching and JavaScript Requirements

Partial Caching is a great tool for speeding up your website - but if done too aggresively your javascript will not be included.

Today I had a problem with my onepage module in comination with a google map page as a onepage slide. The onepage module caches the whole page (with all subpages as slide) in one big cache:

<% cached 'OnePageHolder', $AllChildren.max('LastEdited'), $AllChildren.count(), $ID %>
    <%--content of main page--%>
	

    <% loop $Children %>
        <%--this method renders the child page with a special template--%>
        $OnePageContent 
    <% end_loop %>

<% end_cached %>

This works fine - as long you don't want to use <% require javascript() %> in your template. If you do it'll be called the first time and everything looks fine. But when you hit the cache, it just returns the rendered html, no js is included at the end of body tag, 'cause the template isn't rendered again.

Simply wrapping the require statements in a <% uncached %> block doesn't work either for some reason - unless you add another cache to that template like:

<% uncached %>
<% require javascript(themes/mytheme/javascript/thirdparty/jquery.min.js) %>
//other requirements...
<% end_uncached %>

<% cached "Content", $ID %>


    $Content


    <div class="map-container" data-lat="$GMapLat" data-lng="$GMapLon" data-title="$GMapHeadingTitle">
        <div class="map-popup-content">$PopupContent</div>
    </div>

<% end_cached %>

 

Rate this post (1 rating(s))

Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments