You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2014/06/23 17:59:37 UTC
[2/4] git commit: Set a default max-age of one minute for modules
Set a default max-age of one minute for modules
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/fcf0e3e2
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/fcf0e3e2
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/fcf0e3e2
Branch: refs/heads/master
Commit: fcf0e3e25a8e2b5ffde5371e214a8e484c990065
Parents: b5cf646
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Jun 23 08:40:14 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Jun 23 08:40:14 2014 -0700
----------------------------------------------------------------------
.../main/java/org/apache/tapestry5/SymbolConstants.java | 12 ++++++++++++
.../internal/services/ResourceStreamerImpl.java | 10 ++++++++--
.../java/org/apache/tapestry5/modules/AssetsModule.java | 1 +
3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fcf0e3e2/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
index 4208479..925acc7 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
@@ -490,6 +490,7 @@ public class SymbolConstants
*/
public static final String EXCEPTION_REPORTS_DIR = "tapestry.exception-reports-dir";
+
/**
* Defines whether {@link org.apache.tapestry5.internal.services.assets.CSSURLRewriter} will throw an exception when a CSS file
* references an URL which doesn't exist. The default value is <code>false</code>.
@@ -498,4 +499,15 @@ public class SymbolConstants
*/
public static final String STRICT_CSS_URL_REWRITING = "tapestry.strict-css-url-rewriting";
+ /**
+ * When an asset (typically, a JavaScript module) is streamed without an explicit expiration header, then
+ * this value is sent as the {@code Cache-Control} header; the default is "max-age=60, must-revalidate". Setting
+ * max-age to a value above zero signficantly reduces the number of client requests for module content, as client
+ * browsers will then cache previously downloaded versions. For normal assets, which are immutable, and fingerprinted with
+ * a content hash, there is no need to set max age, and instead, a far-future expiration date is provided.
+ *
+ * @since 5.4
+ */
+ public static final String OMIT_EXPIRATION_CACHE_CONTROL_HEADER = "tapestry.omit-expiration-cache-control-header";
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fcf0e3e2/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
index d2aec0a..d5e6024 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
@@ -46,6 +46,8 @@ public class ResourceStreamerImpl implements ResourceStreamer
private final ResourceChangeTracker resourceChangeTracker;
+ private final String omitExpirationCacheControlHeader;
+
public ResourceStreamerImpl(Request request,
Response response,
@@ -57,7 +59,10 @@ public class ResourceStreamerImpl implements ResourceStreamer
@Symbol(SymbolConstants.PRODUCTION_MODE)
boolean productionMode,
- ResourceChangeTracker resourceChangeTracker)
+ ResourceChangeTracker resourceChangeTracker,
+
+ @Symbol(SymbolConstants.OMIT_EXPIRATION_CACHE_CONTROL_HEADER)
+ String omitExpirationCacheControlHeader)
{
this.request = request;
this.response = response;
@@ -66,6 +71,7 @@ public class ResourceStreamerImpl implements ResourceStreamer
this.tracker = tracker;
this.productionMode = productionMode;
this.resourceChangeTracker = resourceChangeTracker;
+ this.omitExpirationCacheControlHeader = omitExpirationCacheControlHeader;
}
public boolean streamResource(final Resource resource, final String providedChecksum, final Set<Options> options) throws IOException
@@ -166,7 +172,7 @@ public class ResourceStreamerImpl implements ResourceStreamer
// mostly result in quick SC_NOT_MODIFIED responses.
if (options.contains(Options.OMIT_EXPIRATION))
{
- response.setHeader("Cache-Control", "max-age=0, must-revalidate");
+ response.setHeader("Cache-Control", omitExpirationCacheControlHeader);
}
response.setContentLength(streamable.getSize());
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fcf0e3e2/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java
index b6a6b13..4ec8207 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/AssetsModule.java
@@ -79,6 +79,7 @@ public class AssetsModule
configuration.add(SymbolConstants.BOOTSTRAP_ROOT, "${tapestry.asset.root}/bootstrap");
configuration.add("tapestry.asset.root", "classpath:META-INF/assets/tapestry5");
+ configuration.add(SymbolConstants.OMIT_EXPIRATION_CACHE_CONTROL_HEADER, "max-age=60,must-revalidate");
}
// The use of decorators is to allow third-parties to get their own extensions