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

Adds support for additionalManifestEntries build option #2124

Merged
merged 3 commits into from
Jul 18, 2019

Conversation

jeffposnick
Copy link
Contributor

R: @philipwalton

Fixes #1571 by adding in a new additionalManifestEntries option that can be passed in to any of the build tools.

@@ -104,4 +104,10 @@ module.exports = {
'bad-manifest-transforms-return-value': ol`The return value from a
manifestTransform should be an object with 'manifest' and optionally
'warnings' properties.`,
'string-entry-warning': ol`Some URLs were passed to additionalManifestEntries
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interested in feedback here: my thinking is that we can support passing in a string URL, but if someone does that, we should let them know about the potential pitfalls involved with precaching a URL that may or may not be revisioned. They can avoid the warning by explicitly using {url: '...'} as the entry, kind of as a "I know what I'm doing and accept the risks mode."

The thing a like about that approach is that the most likely think developers will do first is pass in a string, and they'll see this warning, and hopefully they'll think about whether it's safe to precache that given URL.

An alternative approach would be to disallow passing in a string entirely, but I'm not sure that would be as... educational?... as this approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another alternative would be to only take in objects with both url and revision properties, and tell developers that they need to explicitly set revision: null if they're sure they're passing in a URL that is already revisioned. That's pretty draconian, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another alternative would be to only take in objects with both url and revision properties

Yeah, I was going to say exactly this. I think it makes sense to allow strings and show the warning, but the way to silence the warning would be to specify revision: null (or false perhaps).

Copy link
Member

@philipwalton philipwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offered a few suggestions based on your questions. Overall the approach seems good to me, and I think the feature is useful.

.gitignore Show resolved Hide resolved
'string-entry-warning': ol`Some URLs were passed to additionalManifestEntries
as strings. Please ensure that these URLs contain versioning info
(e.g. 'https://example.com/v1.0/index.js'), as Workbox cannot maintain
its own revision info for them. To disable this warning, pass in an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider making this possible? It wouldn't be terribly hard for use to add our own revision data to an external URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. Our build tools can't maintain revision info for those URLs, because they're (pretty much by definition) URLs that exist outside of the local build process.

If a developer has their own approach for revisioning these additional URLs then they're free to pass in meaningful info for the revision property instead of null. But in terms of this warning, I'm assuming that if they passed in a string it's because they don't have out-of-band revision info available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make an HTTP request, hash the contents of the response, and then use that as the revision (just as we do with files on the file system).

Then, if the file changes on the external server, a rebuild with the same user input would invalidate the old URL.

I definitely don't think this should be the default behavior; I'm just thinking it might potentially be a nice feature for developers who don't want/know how to do that themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we're opening up a can of worms here, because I really don't want developers to use this with unversioned URLs in the way you describe.

If there's a separate deployment process in place for those additional URLs, and it's not tied to generating the service worker, then developers are inevitably going to get confused when the additional URL is updated and their users don't see any updates until they remember to re-run their build process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, just wanted to make sure you'd considered it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is using webpack's [hash] sufficient enough?

        additionalManifestEntries: [
          { url: '/offline.html', revision: '[hash]'}
        ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have an actual hash value for a given asset derived from the current webpack compilation in a variable, it would be. But the syntax you're using there won't work; workbox-webpack-plugin won't automatically replace '[hash]' inside of additionalManifestEntries for you.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 you're right!
I ended up not needing additionalManifestEntries (for now at least)

@@ -104,4 +104,10 @@ module.exports = {
'bad-manifest-transforms-return-value': ol`The return value from a
manifestTransform should be an object with 'manifest' and optionally
'warnings' properties.`,
'string-entry-warning': ol`Some URLs were passed to additionalManifestEntries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another alternative would be to only take in objects with both url and revision properties

Yeah, I was going to say exactly this. I think it makes sense to allow strings and show the warning, but the way to silence the warning would be to specify revision: null (or false perhaps).

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

File Before After Change GZipped
packages/workbox-strategies/build/workbox-strategies.prod.js 4.10 KB 4.78 KB +16% 1.20 KB ☠️

New Files

No new files have been added.

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.86 KB 3.86 KB 0% 1.59 KB
packages/workbox-broadcast-update/build/workbox-broadcast-update.prod.js 1.92 KB 1.92 KB 0% 959 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 3.30 KB 3.30 KB 0% 1.31 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 594 B 594 B 0% 354 B
packages/workbox-cli/build/app.js 4.15 KB 4.15 KB 0% 1.64 KB
packages/workbox-cli/build/bin.js 940 B 940 B 0% 502 B
packages/workbox-core/build/workbox-core.prod.js 5.94 KB 5.94 KB 0% 2.46 KB
packages/workbox-expiration/build/workbox-expiration.prod.js 2.94 KB 2.94 KB 0% 1.27 KB
packages/workbox-google-analytics/build/workbox-offline-ga.prod.js 1.95 KB 1.95 KB 0% 913 B
packages/workbox-navigation-preload/build/workbox-navigation-preload.prod.js 660 B 660 B 0% 324 B
packages/workbox-precaching/build/workbox-precaching.prod.js 4.25 KB 4.25 KB 0% 1.70 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.57 KB 1.57 KB 0% 797 B
packages/workbox-routing/build/workbox-routing.prod.js 3.41 KB 3.41 KB 0% 1.47 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 4.10 KB 4.78 KB +16% 1.20 KB ☠️
packages/workbox-streams/build/workbox-streams.prod.js 1.46 KB 1.46 KB 0% 720 B
packages/workbox-sw/build/workbox-sw.js 1.34 KB 1.34 KB 0% 747 B
packages/workbox-webpack-plugin/build/generate-sw.js 3.13 KB 3.13 KB 0% 1.22 KB
packages/workbox-webpack-plugin/build/index.js 349 B 349 B 0% 255 B
packages/workbox-webpack-plugin/build/inject-manifest.js 4.67 KB 4.67 KB 0% 1.59 KB
packages/workbox-window/build/workbox-window.dev.umd.js 31.88 KB 31.88 KB 0% 8.10 KB
packages/workbox-window/build/workbox-window.prod.umd.js 4.46 KB 4.46 KB 0% 1.84 KB

Workbox Aggregate Size Plugin

3.49KB gzip'ed (23% of limit)
7.8KB uncompressed

@jeffposnick jeffposnick merged commit 3f23e24 into master Jul 18, 2019
@jeffposnick jeffposnick deleted the additional-manifest-entries branch July 18, 2019 19:35
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

Successfully merging this pull request may close these issues.

Support for a new additionalManifestEntries build tool option
4 participants