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

manifestTransforms does nothing #2243

Closed
rafzan opened this issue Oct 3, 2019 · 3 comments
Closed

manifestTransforms does nothing #2243

rafzan opened this issue Oct 3, 2019 · 3 comments

Comments

@rafzan
Copy link

rafzan commented Oct 3, 2019

Library Affected:
workbox-webpack-plugin

Browser & Platform:
all browsers (happens on build)
Node v12.7.0

Issue or Feature Request Description:
Not much to add here. manifestTransforms does absolutely nothing, not even logs on terminal.

Here's my InjectManifest:

new WorkboxPlugin.InjectManifest({
            swSrc: "./assets/js/pwa/worker.js",
            swDest: "sw.js",
            precacheManifestFilename: "precache.[manifestHash].js",
            excludeChunks: ["one", "two", "three"],
            include: [
                /(vendor).*\.js(?=\?|$|)/,
                /\.(woff2)(?=\?|$|)/
            ],
            exclude: [
                "avatar_empty.svg",
                "favicon-512x512.png",
                "favicon-192x192.png",
            ],
            manifestTransforms: [
                // Dirty akamai fix: removing __WB_REVISION__ from fetch URLs
                originalManifest => {
                    const result = originalManifest.map(entry => new Object({ url: entry.url }))
                    return { manifest: result, warnings: [] };
                }
            ]
        })
@jeffposnick
Copy link
Contributor

Prior to Workbox v5, for legacy compatibility, manifestTransforms in the webpack plugin would only operate on URLs matched via glob patterns—not URLs derived from webpack assets. This obviously makes the option much less useful than it could be.

Starting with Workbox v5 (currently in pre-release), manifestTransforms will operate as you expect (and we've removed the ability to pick up non-webpack assets via glob patterns).

You can read more about that change in the pre-release notes.

I would recommend trying out Workbox v5, as we're getting fairly close to a final release, especially if you need that functionality.

@rafzan
Copy link
Author

rafzan commented Oct 4, 2019

Actually, I'm trying to remove the ?__WB_REVISION__=... query string from the cached assets requests (our akamai config will create new cache entries for those), and the only way we found was adding this map on our service-worker.js file:

workbox.precaching.precacheAndRoute(
    self.__precacheManifest.map(entry => new Object({ url: entry.url }))
);

Very dirty fix. Is there any better way to achieve this?
Thank you so much!

@jeffposnick
Copy link
Contributor

The point of the ?__WB_REVISION= parameters is to bypass existing cache entries for URLs that Workbox believes do not contain any revision info already.

However, Workbox v4 wasn't always able to automatically detect which URLs originating from webpack assets included [hash]s as part of their names, leading to false positives.

In Workbox v5, you can use dontCacheBustURLsMatching: new RegExp(...) to specifically tell Workbox what your [hash]ed filename pattern looks like, so that it knows those URLs include revision info and don't need to be cache-busted. (Once #2221 is addressed, Workbox will be able to do this automatically in a reliable way, without any configuration.)

Furthermore, in the latest Workbox v5 pre-release, we stopped adding in ?__WB_REVISION= URL query parameters altogether, even for URLs that need to be cache-busted, in favor of setting the cache mode on the outgoing request to indicate that the response shouldn't be returned by any intermediary caches.

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

2 participants