From 97dfcf43aee9d4e509acb5a2daa1c85f73f52337 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 11 Nov 2017 19:24:47 +0100 Subject: [PATCH] Removed http/2 push for service worker prefetches --- main.go | 5 +++++ sw/service-worker.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d863831e..0629a0a0 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,11 @@ func configure(app *aero.Application) *aero.Application { // Prefetch all collections arn.DB.Prefetch() + // Do not use HTTP/2 push on service worker requests + app.AddPushCondition(func(ctx *aero.Context) bool { + return ctx.Request().Header().Get("X-Source") != "service-worker" + }) + // Specify test routes for route, examples := range routeTests { app.Test(route, examples) diff --git a/sw/service-worker.ts b/sw/service-worker.ts index 65cbd379..237d67a1 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -211,8 +211,14 @@ class MyServiceWorker { prefetchFullPage(url: string) { let fullPage = new Request(url.replace("/_/", "/")) + // Disable HTTP/2 push responses + let headers = new Headers({ + "X-Source": "service-worker" + }) + let fullPageRefresh = fetch(fullPage, { - credentials: "same-origin" + credentials: "same-origin", + headers }).then(response => { // Save the new version of the resource in the cache let cacheRefresh = caches.open(this.cache.version).then(cache => {