From 81ffe0583462ca270d09a5dbc79db39d8d8685e0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 25 Nov 2017 14:11:55 +0100 Subject: [PATCH] Improved push conditions --- main.go | 4 +++- sw/service-worker.ts | 8 +------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index a7dc8b17..efe7e943 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "strings" + "github.com/aerogo/aero" "github.com/aerogo/session-store-nano" "github.com/animenotifier/arn" @@ -68,7 +70,7 @@ func configure(app *aero.Application) *aero.Application { // 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" + return !strings.Contains(ctx.Request().Header().Get("Referer"), "/service-worker") }) // Specify test routes diff --git a/sw/service-worker.ts b/sw/service-worker.ts index 4d6deee4..a805d2b5 100644 --- a/sw/service-worker.ts +++ b/sw/service-worker.ts @@ -211,14 +211,8 @@ 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", - headers + credentials: "same-origin" }).then(response => { // Save the new version of the resource in the cache let cacheRefresh = caches.open(this.cache.version).then(cache => {