-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for HTTP/2 #1451
Comments
I'm adding the |
This is currently not possible as polka (current server in use) does not support http2. Maybe we can get a polka update with an http2 option.... |
I created a feature request there: lukeed/polka#162 Since http2 is already supported by Node.js, it's more a framework and design decision for polka. edit:
|
With this doc: https://github.com/sveltejs/kit/tree/master/packages/adapter-node#custom-server |
The pull request was denied, one of the reasons was TLS. Maybe it would be possible to start without TLS? Enable HTTP/2.0 (h2c) without TLS in SvelteKit, so users can benefit from decreased latencies and improved page load speeds. With this the usual reverse proxy can handle TLS, and we can still benefit from the http/2 speed improvements on the internal network. Reference: HTTP/2.0 h2c on Wikipedia |
@bluepuma77 Your best bet is just using a custom server, they're not gonna add built-in support for this. |
http/2 in unencrypted cleartext (h2c) works on Node 20.12.0 and earlier with a custom polka server. Support broke between v20.12.0 to v20.12.1, which was discussed over here: #11365 (comment) Anyway, for the record, here is how I run h2c on node v20.12.0:
import polka from 'polka';
import http2 from 'node:http2';
import { handler } from './build/handler.js';
import { env } from './build/env.js';
const path = env('SOCKET_PATH', false);
const host = env('HOST', '0.0.0.0');
const port = env('PORT', !path && '3000');
// Note: http2.createServer() is unencrypted and will not work in any browser
// This server should be behind a reverse proxy (eg. NGINX) with SSL termination.
const server = polka({ server: http2.createServer() })
.use(handler)
.listen({ path, host, port }, () => {
console.log(`Listening on ${path ? path : host + ':' + port}`);
});
const sessions = new Set();
server.server.on('session', (session) => {
sessions.add(session);
session.on('close', () => {
sessions.delete(session);
});
});
function shutdown() {
server.server.close(() => {
console.log('Server has closed.');
});
for (const session of sessions) {
session.close();
}
}
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
process.on('exit', () => {
console.log('Process is exiting.');
});
Again, the above will only work in Node 20.12.0 and below, unfortunately. Running an old version of Node is probably not the best idea long-term, so it would be nice with a better solution for h2c http/2. (PS. I'm using Google Cloud Run for end-to-end http/2 which requires h2c for it to work) |
I just did a test with Lighthouse (Desktop) and it showed incredibely nice results on the first try. This is really awesome.
![image](https://user-images.githubusercontent.com/20150243/118299571-33861a80-b4e1-11eb-9501-55fb585ba434.png)
For the Performance section the major penalty was missing HTTP\2
![image](https://user-images.githubusercontent.com/20150243/118299726-65977c80-b4e1-11eb-9d3f-758355950b5c.png)
Describe the solution you'd like
I'd like to have an option to activate HTTP\2 via config.
The text was updated successfully, but these errors were encountered: