Skip to content

Instantly share code, notes, and snippets.

@kristoferbaxter
Created July 19, 2011 08:06
Show Gist options
  • Save kristoferbaxter/1091672 to your computer and use it in GitHub Desktop.
Save kristoferbaxter/1091672 to your computer and use it in GitHub Desktop.
Multikey Caching Proposal
A modest multikey caching proposal.
Allow the page to set valid hosts which share the same cache entry for resources. A request to foo.bar/baz is also cached for foo2.bar/baz.
Limitations to multikey caching: Only urls from the same root domain can be used. A request to the browser to specify foo.bar/baz is the same as www.google.com/baz would not be allowed. In this example, www.google.com/baz and www2.google.com/baz would work.
Format consists of a few pieces.
1. Meta tag in markup defining what Wildcard pattern to iterate over. This can be a comma separated list, or include a regular expression.
2. Each request from the browser in a multikey request includes a specific header stating the host pattern of the document including this asset.
3. Responses much have the exact key match as the host document.
If any of these parts is not in order, then caching for that entry is reverted to single key.
<html>
<head>
<meta name="X-Cache-Hosts" content="image{/[0-9]*/}.foo.com" />
<link href="http://{X-Cache-Hosts}/css/screen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
<img src="http://{X-Cache-Hosts}/path/to/image.png" />
</body>
</html>
Request:
http://image0.foo.com/css/screen.css
X-Cache-Hosts: image{/[0-9]*/}.foo.com
Response:
body{display:block}
X-Cache-Sources: image{/[0-9]*/}.foo.com
Advantages:
The browser is responsible for parallel downloading assets it currently doesn't have cached. Servers and scripts inserting assets requiring an extra request need not worry about trying to parallelize downloads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment