Skip to content
This repository was archived by the owner on May 2, 2022. It is now read-only.

Conversation

@ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Sep 24, 2020

Fixes #50.

At the moment, the filename of a bundle is always different each time bundling is performed, even if the Edge handlers source files have not changed. This might be a problem:

  • This creates unnecessary additional bundles in .netlify/edge-handlers/ even when nothing has changed
  • This prevents using the bundle filename as an indication of whether any Edge handlers contents has changed, which could be interesting as a performance/caching optimization

The reason the bundle filename always changes is because each Edge handler is exported using a unique ID. That ID is part of the final bundle and is randomly generated.

This PR solves this problem by generating this unique ID by performing a SHA1 cheksum on the Edge handler filename instead.
If any Edge handler source file's contents changes, the bundle filename will still change since it is based not only on each generated ID, but also on a concatenation of all Edge handlers source files.

One side-effect this PR is that id in netlifyRegistry.set("handlerFilename", "id") will remain the same across builds if the handler filename has not changed. However, it is guaranteed to be unique within a specific build, since two Edge handlers cannot have the same filename (full file paths can also be used in the future). Please let me know if this is a problem with how netlifyRegistry is implemented. I am guessing not but I want to confirm.

@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Sep 24, 2020
@ehmicky ehmicky self-assigned this Sep 24, 2020
Copy link
Contributor

@calavera calavera left a comment

Choose a reason for hiding this comment

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

👌

@ehmicky ehmicky merged commit 90a1368 into master Sep 25, 2020
@ehmicky ehmicky deleted the feat/consistent-bundle-filename branch September 25, 2020 12:54
@mraerino
Copy link
Contributor

oh, this is very valuable. thank you!

This was referenced Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

type: feature code contributing to the implementation of a feature and/or user facing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundles checksum should remain the same when the handler did not change

4 participants