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

♻️🏗 Allow dead-code-eliminating config.urls #37998

Merged
merged 17 commits into from
Apr 5, 2022

Conversation

alanorozco
Copy link
Member

@alanorozco alanorozco commented Apr 1, 2022

Refactors config.urls so that they can be dead-code-eliminated.

Nearly all bundles change from -0.15kb to -0.38kb. Runtimes change by +0.01kb.

  var J =
-     self.AMP_CONFIG || {},
+     (t) => (self.AMP_CONFIG ? self.AMP_CONFIG[t] : null),
    K =
-     ('string' == typeof J.cdnProxyRegex
-       ? new RegExp(J.cdnProxyRegex)
-       : J.cdnProxyRegex) ||
+     ('string' == typeof J('cdnProxyRegex')
+       ? new RegExp(J('cdnProxyRegex'))
+       : J('cdnProxyRegex')) ||
      /^https:\/\/([a-zA-Z0-9_-]+\.)?cdn\.ampproject\.org$/,
-   T =
-     ('string' == typeof J.thirdPartyFrameRegex
-       ? new RegExp(J.thirdPartyFrameRegex)
-       : J.thirdPartyFrameRegex) || /^d-\d+\.ampproject\.net$/;
    Q = 
-     {
-       thirdParty: J.thirdPartyUrl || 'https://3p.ampproject.net',
-       thirdPartyFrameHost: J.thirdPartyFrameHost || 'ampproject.net',
-       thirdPartyFrameRegex: T,
-       cdn: J.cdnUrl || Z('runtime-host') || 'https://cdn.ampproject.org',
-       cdnProxyRegex: X,
-       localhostRegex: /^https?:\/\/localhost(:\d+)?$/,
-       errorReporting:
-         J.errorReportingUrl ||
-         'https://us-central1-amp-error-reporting.cloudfunctions.net/r',
-       betaErrorReporting:
-         J.betaErrorReportingUrl ||
-         'https://us-central1-amp-error-reporting.cloudfunctions.net/r-beta',
-       localDev: J.localDev || !1,
-       trustedViewerHosts: [
-         /(^|\.)google\.(com?|[a-z]{2}|com?\.[a-z]{2}|cat)$/,
-         /(^|\.)gmail\.(com|dev)$/,
-       ],
-       geoApi: J.geoApiUrl || Z('amp-geo-api'),
-     };
+     J('cdnUrl') || Z('runtime-host') || 'https://cdn.ampproject.org';

@alanorozco alanorozco requested review from samouri and jridgewell April 1, 2022 20:40
@alanorozco alanorozco marked this pull request as ready for review April 1, 2022 20:40
@amp-owners-bot
Copy link

amp-owners-bot bot commented Apr 1, 2022

Hey @erwinmombay! These files were changed:

build-system/babel-plugins/babel-plugin-deep-pure/index.js
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/error-member-expression/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/error-member-expression/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/output.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/output.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/output.mjs
+6 more

Hey @jridgewell! These files were changed:

build-system/babel-plugins/babel-plugin-deep-pure/index.js
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/error-member-expression/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/error-member-expression/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-import-source/output.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/ignored-not-import/output.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/input.mjs
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/options.json
build-system/babel-plugins/babel-plugin-deep-pure/test/fixtures/transform/transform-aliased-path/output.mjs
+7 more

Hey @gmajoulet, @mszylkowski! These files were changed:

extensions/amp-cache-url/0.1/amp-cache-url.js
extensions/amp-story-dev-tools/0.1/amp-story-dev-tools-tab-debug.js

src/config/urls.js Outdated Show resolved Hide resolved
src/config/urls.js Outdated Show resolved Hide resolved
@alanorozco alanorozco merged commit cb67fc9 into ampproject:main Apr 5, 2022
@alanorozco alanorozco deleted the urls branch April 5, 2022 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants