Enabling browser cache

Sometimes it is wise to enable browser cache so that the web browser would rather use memory cached page than get it from the website. You could for example use this method to make browser to "remember" the form fields values when returning to the form after a warning message when the user has not filled all mandatory inputs.

To do so, you need to send appropriate HTTP header to the browser. The following example sends correct header when the user is browsing object with ID = 1234 (eg. www.site.com/?id=1234) and the current user is not content editor.

{* You need to insert this code BEFORE the <!doctype..> declaration and <html> tag *}
{* The page is cached in browser for 300 seconds *}

{if $id == 1234 && !$admin}
    {assign var="max_age" value=300}
    {assign var="date_format" value="D, d M Y H:i:s"}
    {assign var="Last_Modified" value=$date_format|@date:$smarty.now}
    {math equation="x + y" x=$smarty.now y=$max_age assign="Expires"}
    {assign var="Expires" value=$date_format|@date:$Expires}

    {insert name=header content="Pragma: public"}
    {insert name=header content="Last-Modified: `$Last_Modified` GMT"}
    {insert name=header content="Expires: `$Expires` GMT"}
    {insert name=header content="Cache-Control: public, max-age=`$max_age`, pre-check=`$max_age`"}
{/if}

Site development

About Saurus API / Creating page template tutorial / Creating content template tutorial / Applying custom design to page template checklist / Moderated comments / Stationary articles (header, footer etc) / First, last and n'th item in a foreach loop / Creating zebra tables (cycling values) / Site and Article editor CSS styles / How to set up website aliases / Customising v-shaped editor buttons / Using PHP in templates / Exchanging variables between templates and PHP / Profiles and Custom Assets / Site languages / Printer friendly pages / Enabling browser cache / Creating WAP pages / Configuring sitemap / Saurus 4.1 technical notes