Permalink
Browse files

caching static pages

  • Loading branch information...
MarkiyanMatsekh committed Nov 14, 2012
1 parent 48f247d commit 1c20f62e146fd73b827c61c48dae661ed52e5771
@@ -49,9 +49,15 @@ public static ResponseConfiguration Ok(HttpEntity entity, Message message)
public static ResponseConfiguration OkCache(HttpEntity entity, Message message, int seconds)
{
+ return OkCache(entity.ResponseCodec.ContentType, seconds);
+ }
+
+ public static ResponseConfiguration OkCache(string contentType, int seconds)
+ {
+ // note MM: in old browsers Expires header maybe be required
return new ResponseConfiguration(HttpStatusCode.OK,
"OK",
- entity.ResponseCodec.ContentType,
+ contentType,
new KeyValuePair<string, string>("Cache-Control", string.Format("max-age={0}", seconds)));
}
@@ -105,9 +105,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
}
else
{
+ var config = GetWebPageConfig(contentType);
var content = File.ReadAllBytes(fullPath);
- http.Manager.Reply(content, 200, "OK", contentType, null,
- ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
+
+ http.Manager.Reply(content,
+ config.Code,
+ config.Description,
+ config.Type,
+ config.Headers,
+ ex => _logger.InfoException(ex, "Error while replying from MiniWeb"));
}
}
catch (Exception ex)
@@ -116,6 +122,15 @@ private void ReplyWithContent(HttpEntity http, string contentLocalPath)
}
}
+ private static ResponseConfiguration GetWebPageConfig(string contentType)
+ {
+#if RELEASE || CACHE_WEB_CONTENT
+ return Configure.OkCache(contentType, 60 * 60); //1 hour
+#else
+ return Configure.OkNoCache(contentType);
+#endif
+ }
+
public static string GetWebRootFileSystemDirectory(string debugPath = null)
{
string fileSystemWebRoot = null;
@@ -10,6 +10,10 @@ es.tmpl = (function () {
registerOnLoad();
+ $.ajaxSetup({
+ cache: 'default' // prevent adding ?_=timestamp by jquery
+ });
+
return {
renderHead: renderHead,
renderBody: renderBody,
@@ -1,4 +1,5 @@
<meta charset="utf-8"/>
+ <link rel="shortcut icon" href="/web/es/img/favicon.ico" type="image/x-icon" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
@@ -17,4 +18,3 @@
<![endif]-->
<!-- icons -->
-<link rel="shortcut icon" href="/web/es/img/favicon.ico"/>

0 comments on commit 1c20f62

Please sign in to comment.