Skip to content

Instantly share code, notes, and snippets.

@rezan
Created April 18, 2019 00:06
Show Gist options
  • Save rezan/c4a7237db2c9a0264340303393a72d00 to your computer and use it in GitHub Desktop.
Save rezan/c4a7237db2c9a0264340303393a72d00 to your computer and use it in GitHub Desktop.
Live prefetching
# Live prefetching
vcl 4.1;
import http;
import kvstore;
sub vcl_init
{
new limit = kvstore.init();
}
sub vcl_recv
{
# Generate the prefetch URL
set req.http.X-prefetch = http.prefetch_next_url(prefix = "/.*/dash/[0-9]+-[0-9]+/");
# Only prefetch once per 3s
if (limit.counter(req.http.X-prefetch, 1, 3s) == 1) {
http.init(0);
http.req_copy_headers(0);
http.req_set_method(0, "HEAD");
http.req_set_url(0, req.http.X-prefetch);
http.req_send_and_finish(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment