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

♻️📖 amp-geo refactor to remove need for empty config and reduce minified code size #14670

Merged
merged 9 commits into from Apr 17, 2018

Conversation

jpettitt
Copy link
Contributor

@jpettitt jpettitt commented Apr 17, 2018

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.

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

this.matchedGroups_.push(groups[i]);
isArray(ISOCountryGroups[group]),
`${errorPrefix}[${group}] must be an array`);
if (ISOCountryGroups[group].indexOf(this.country_) >= 0) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

@rsimha
Copy link
Contributor

rsimha commented Apr 17, 2018

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.

@rsimha rsimha merged commit 2d6f60f into ampproject:master Apr 17, 2018
rsimha pushed a commit that referenced this pull request Apr 17, 2018
…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
glevitzky pushed a commit that referenced this pull request Apr 27, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants