Created
April 18, 2019 00:06
-
-
Save rezan/c4a7237db2c9a0264340303393a72d00 to your computer and use it in GitHub Desktop.
Live prefetching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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