Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make URLs immutable #4

Closed
simonw opened this issue Oct 23, 2017 · 8 comments
Closed

Make URLs immutable #4

simonw opened this issue Oct 23, 2017 · 8 comments

Comments

@simonw
Copy link
Owner

simonw commented Oct 23, 2017

Absolutely everything should have a far-future expires header

Part of the URL will be the truncated sha1 hash of the database file itself, calculated at build time

@simonw simonw changed the title Absolutely everything should have a far-future expires header Make URLs immutable Oct 23, 2017
@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

This means I need a good solution for these compile time options while running in development mode

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

How about when the service starts up it checks for a compile.json file and, if it is missing, creates it using the same code we run at compile time normally

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

Many of the applications I want to implement with this would benefit from having permanent real URLs.

So let’s have both. The sha1 urls will serve far future cache headers (and an etag derived from their path). The non sha1 URLs will serve 302 uncached redirects to the sha1 locations.

We will have a setting that lets people opt out of this behavior.

@simonw simonw added this to the Ship v1 milestone Oct 23, 2017
@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

URL design:

 /database/table.json - redirects to /database-6753f4a/table.json

So we always redirect to the version with the truncated hash in the URL.

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

https://stackoverflow.com/a/18134919/6083 is a good answer about how many characters of the hash are needed to be unique. I say we default to 7 characters, like git does - but allow extras to be configured.

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

Can I take advantage of HTTP/2 so even if you get redirected I start serving you the correct resource straight away?

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

Looks like the easiest way to implement HTTP/2 server push today is to run behind Cloudflare and use this:

Link: </asset/to/push.js>; rel=preload; as=script

https://blog.cloudflare.com/announcing-support-for-http-2-server-push-2/

Here's the W3C draft: https://w3c.github.io/preload/

From https://w3c.github.io/preload/#as-attribute it looks like I should use as=fetch if the content is intended for consumption by fetch() or XMLHTTPRequest.

Unclear if I should throw as=fetch crossorigin in there. Need to experiment on that.

@simonw
Copy link
Owner Author

simonw commented Oct 23, 2017

Here's what the homepage of cloudflare.com does (with newlines added within the link header for clarity):

$ curl -i 'https://www.cloudflare.com/' 
HTTP/1.1 200 OK
Date: Mon, 23 Oct 2017 21:45:58 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
link:
    </vendor/bitdashplayer.min.css>; rel=preload; as=style,
    </vendor/bitdash-controls.min.css>; rel=preload; as=style,
    </video/marketing-video/cloudflare-marketing-video.mpd>; rel=preload,
    </video/marketing-video/cloudflare-marketing-video.m3u8>; rel=preload,
    </video/marketing-video/video_0_800000/dash/init.mp4>; rel=preload; as=video,
    </video/marketing-video/audio_0_128000/dash/init.mp4>; rel=preload; as=video,
    </video/marketing-video/video_0_800000/dash/segment_0.m4s>; rel=preload; as=video,
    </video/marketing-video/audio_0_128000/dash/segment_0.m4s>; rel=preload; as=video,
    </video/new-short-optimized-22.mp4>; rel=preload; as=video,
    </video/marketing-video/poster.jpg>; rel=preload; as=image

The original header looked like this:

link: </vendor/bitdashplayer.min.css>; rel=preload; as=style, </vendor/bitdash-controls.min.css>; rel=preload; as=style, </video/marketing-video/cloudflare-marketing-video.mpd>; rel=preload, </video/marketing-video/cloudflare-marketing-video.m3u8>; rel=preload, </video/marketing-video/video_0_800000/dash/init.mp4>; rel=preload; as=video, </video/marketing-video/audio_0_128000/dash/init.mp4>; rel=preload; as=video, </video/marketing-video/video_0_800000/dash/segment_0.m4s>; rel=preload; as=video, </video/marketing-video/audio_0_128000/dash/segment_0.m4s>; rel=preload; as=video, </video/new-short-optimized-22.mp4>; rel=preload; as=video, </video/marketing-video/poster.jpg>; rel=preload; as=image

@simonw simonw closed this as completed in 12f7e1d Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant