Footer Caching Workaround.. what's the right way to do this?

I have the following chunk of code in my footer.phtml

 <!-- Customer Modal -->
 <?php if (array_key_exists("customer_select", $_COOKIE) == FALSE ): ?>
    <script type="text/javascript" src="<?=$this->getSkinUrl('js/jqModal.js')?>"></script>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery("#customer_type_dialog").jqm().jqmShow();
        });
    </script>
    <?php include("../../templates.eu/templates.sbc.de/_includes/customer_select.php"); ?>
<?php endif; ?>

When I turn on the block caching it stops evaluating this an only returns the value that was cached. HOw do I work around this problem or what is a better way to do this? Basically I’m checking to see if a cookie exists and if it does I’m adding some js and another file to the page.

One thought on “Footer Caching Workaround.. what's the right way to do this?”

  1. Put the above code in it’s own template file and make this layout change:

    <reference name="before_body_end">
        <block type="core/template" template="your/cookie/check/file.phtml" />
    </reference>
    

    This way the footer gets to be cached (which helps keep pages fast) and your cookie check is evaluated each time. Also the Javascript is left until the last possible point of the page which is a best practice for inline scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *