Setting Last-modified http header via xslt Options
Arjandb
Posted: Sunday, March 09, 2008 2:45:09 PM
Rank: Devotee

Joined: 8/31/2007
Posts: 50
Location: Utrecht NL
I made a macro which sets the Last-modified http header of Umbraco pages to Umbraco's @updateDate. This caches unmodified pages on the client side, which improves speed and reduces bandwidth on the server. I thought this might be interesting for others, or someone has an even better method?

Below is the basic pinciple. I did make a more advanced version that also takes the updateDate from childnodes, which are displayed as menu items on my pages - so these should also trigger a new Last-modified date. But for clearity, the below example is only for the current page:

Code:

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:hua="abc:yoursite-com:xslt"
exclude-result-prefixes="msxml umbraco.library abc">
...

<xsl:value-of select="abc:setModif($currentPage/@updateDate)"/>

...

<msxsl:scr<!-- remove -->ipt language="VB" implements-prefix="abc">
<msxsl:assembly name="System.Web"/>
<!-- assembly reference generates error while saving, so use Skip testing (ignore errors) - not ideal though... -->
<![CDATA[

public Function setModif(dat As String)
  Dim mDat As DateTime = Convert.ToDateTime(dat).ToUniversalTime
  System.Web.HttpContext.Current.Response.AddHeader("Last-modified", mDat.ToString("r"))
  'Return mDat.ToString("r") 'use for debugging
  Return ""
End Function

]]>

</msxsl:script>

</xsl:stylesheet>
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.