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

Golfing #15

Merged
merged 18 commits into from
Dec 11, 2018
Merged

Golfing #15

merged 18 commits into from
Dec 11, 2018

Conversation

lukeed
Copy link
Contributor

@lukeed lukeed commented Dec 11, 2018

Sorry for the long-ish PR, but I wanted to break apart each step to document its savings as well make it easier to discuss/revert individual changes. If this is to be accepted, I'd recommend squashing.

Also, the spacing is a mess 🙈 The src/.editorconfig looks to be misconfigured or in the wrong place & I didn't want to adjust it as it'd add PR noise, making the 🏌️hard to see.

The core functionality is preserved at 735 B (gz) / 601 B (br) – down from 902 B (gz) / 747 B (br). It's possible to get it down to 717 gz / 594 br by inlining the options defaults, but that may not read as well 😄

There is 1 breaking change (which, of course, I can revert): The priority option is now a Boolean. Not only did this save ~30 bytes, but IMO it makes more sense since the only options were "high" vs "low". In this format, options.priority=true is "high" priority.

The other big wins came from:

  • turning the AsyncFunction into a regular function that returned the Promise
  • dropping link.setAttributes in favor of using link[key] directly
  • using document.head and document.querySelector

@@ -42,14 +42,14 @@ function prefetcher(url) {
* @param {Object} options - Configuration options for quicklink
* @param {Array} options.urls - Array of URLs to prefetch (override)
* @param {Object} options.el - DOM element to prefetch in-viewport links of
* @param {string} options.priority - Attempt to fetch with higher priority (low or high)
* @param {Boolean} options.priority - Attempt higher priority fetch (low or high)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I initially planned for priority to have a tri (or more) state set of values, but it's very likely to stay at either high or low. With that in mind, strongly in favor of switching to a Boolean here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, gotcha. I didn't even know there could be other priorities 😆

@addyosmani
Copy link
Collaborator

src/.editorconfig

I think this snuck in after adopting microbundle 😋. I'll have to fix up or ignore after landing this change.

@lukeed
Copy link
Contributor Author

lukeed commented Dec 11, 2018

Haha, it's happened to me before too. I can fix it up for you after if you'd like.

Copy link
Collaborator

@addyosmani addyosmani left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for working on all of these ⛳️ improvements, @lukeed!

@addyosmani addyosmani merged commit 52201ff into GoogleChromeLabs:master Dec 11, 2018
addyosmani added a commit that referenced this pull request Dec 11, 2018
This change fixes some of the mixed tabs and spaces from the last PR. Unfortunately ESLint doesn't support fixing these automatically (so npm run lint-fix doesn't help here). We should probably fix the editorconfig soonish :)
@lukeed lukeed deleted the golf branch December 11, 2018 18:28
@lukeed
Copy link
Contributor Author

lukeed commented Dec 11, 2018

Awesome, thank you! 🙇

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.

2 participants