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
♻️📖 amp-geo refactor to remove need for empty config and reduce minified code size #14670
Conversation
extensions/amp-geo/0.1/amp-geo.js
Outdated
@@ -152,24 +153,24 @@ export class AmpGeo extends AMP.BaseElement { | |||
*/ | |||
matchCountryGroups_(config) { | |||
/* ISOCountryGroups are optional but if specified at least one must exist */ | |||
if (config.ISOCountryGroups) { | |||
const ISOCountryGroups = config.ISOCountryGroups; | |||
const errorPrefix = '<amp-geo> ISOCountryGroups'; // code size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Micro opts like this aren't worth it. The GZIP differences will be minimal, and it just increases code-read burden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one saved 50 bytes.
extensions/amp-geo/0.1/amp-geo.js
Outdated
this.matchedGroups_.push(groups[i]); | ||
isArray(ISOCountryGroups[group]), | ||
`${errorPrefix}[${group}] must be an array`); | ||
if (ISOCountryGroups[group].indexOf(this.country_) >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Array#includes
is polyfilled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
All tests passed on Travis. The redness in https://travis-ci.org/ampproject/amphtml/jobs/367837186 is coming from Sauce Labs, and is unrelated to the actual tests. Merging this PR. |
…ied code size (#14670) * line length, typo * Refactor to reduce minified size by 10%, make jsons config options, doc to match. * touchups * mitigate possible publisher script injection vector * tighten up regex * test for invalid group * indexOf -> array includes
…ied code size (#14670) * line length, typo * Refactor to reduce minified size by 10%, make jsons config options, doc to match. * touchups * mitigate possible publisher script injection vector * tighten up regex * test for invalid group * indexOf -> array includes
Removes the need for an empty
<script>
with an empty object in it for default config.Multiple refactors to reduce code size after minification (5853 bytes to -> 5318 bytes 9.1% reduction)
Adjust doc accordingly.