Improved push conditions

This commit is contained in:
Eduard Urbach 2017-11-25 14:11:55 +01:00
parent 85a26a5c5b
commit 81ffe05834
2 changed files with 4 additions and 8 deletions

View File

@ -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

View File

@ -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 => {