Content Rewriter Feature
From OpenSocial
Contents |
Summary
Add support for rewriting the content of a generated gadget and allow developers to control how the behavior of the rewriter by introducing a new standard optional gadget feature *content-rewrite*. The content-rewrite feature defines a set of rewriting operations that a container can perform on rendered and proxied content and rules to allow developers to control which content the rewriter can operate on
Spec Updates
http://sites.google.com/site/opensocialdraft/Home/gadgets-api-specification
Definition
The rewriter feature has the general form :
<Optional feature="content-rewrite">
<Param name="expires">86400</Param>
<Param name="include-url"></Param>
<Param name="exclude-url">excluded</Param>
<Param name="exclude-url">moreexcluded</Param>
<Param name="minify-css">true</Param>
<Param name="minify-js">true</Param>
<Param name="minify-html">true</Param>
</Optional>
The parameters are defined as follows:
- expires - The duration in seconds to force as minimum HTTP cache time for content fetched through the proxy via a rewritten URL. Default 86400
- include-url - Any URL which contains this parameters value as a case-insensitive substring is considered rewriteable. The literal string "*" is a special case and implies all URLs. If not specified an entry with the value "*" is assumed. This parameter can be repeated
- exclude-url - Any URL which contains this parameters value as a case-insensitive substring is excluded from rewriting. The literal string "*" implies all URLs and effectively disables all rewriting. This parameter can be repeated.
- minify-css - Controls whether the container will attempt to minify css in style tags and referenced css files. Valid values are "true"|"false". Default is "true"
- minify-js - Controls whether the container will attempt to minify JS in script tags and referenced JS files. Valid values are true|false. Valid values are "true"|"false". Default is "true"
- minify-html - Controls whether the container will attempt to minify HTML content. Valid values are true|false. Valid values are "true"|"false". Default is "true"
Matches for "exclude-url" take precedence over matches for "include-url"
Note that the special use of "*" to denote all URLs should not be interpreted as support for GLOB or RegEx matching on strings.
Containers are free to perform additional optimizations when rewriting links including but not limited to:
- Extract @import directives from style tags and convert them into link tags in the head tag of the containing HTML content
- Merge multiple CSS fetches from successive link tags into one link tag that causes the proxy to concatenate the content fetched from the individual URLs
- Merge contiguous <srcipt src=xxx> tags into one concatenating proxy fetch
Examples
Rewrite only gif images:
<Optional feature="content-rewrite">
<Param name="include-url">.gif</Param>
</Optional>
Rewrite only gif images that do not contain "animated" or "cdn":
<Optional feature="content-rewrite">
<Param name="include-url">.gif</Param>
<Param name="exclude-url">animated</Param>
<Param name="exclude-url">cdn</Param>
</Optional>
Disable all rewriting:
<Optional feature="content-rewrite">
<Param name="exclude-url">*</Param>
</Optional>
