optimizer: Make dynamic component URL rewrites optional#518
optimizer: Make dynamic component URL rewrites optional#518sebastianbenz merged 1 commit intoampproject:masterfrom mattwomple:patch-2
Conversation
|
This is ready for review, with the caveat that it has been written with #517 as its base. |
sebastianbenz
left a comment
There was a problem hiding this comment.
Looks good except: I think this behavior should be supported by versioned and unversioned runtime artifacts (or am I missing anything?).
Otherwise few nits.
packages/optimizer/README.md
Outdated
|
|
||
| **Notice:** The behavior of `ampUrlPrefix` when used in conjunction with `ampRuntimeVersion` changed beginning with version 2.0. Prior to 2.0, `rtv/{rtv}/` was automatically appended to `ampUrlPrefix` when `ampRuntimeVersion` was specified. Since version 2.0, `ampUrlPrefix` is not modified when `ampRuntimeVersion` is also specified. | ||
|
|
||
| - `rewriteDynamicComponents`: When used in conjunction with `ampUrlPrefix`, this option can be set to `false` to prevent [dynamic AMP components](https://github.com/ampproject/amphtml/blob/master/spec/amp-cache-guidelines.md#guidelines-adding-a-new-cache-to-the-amp-ecosystem) from having their URLs rewritten. This option is only effective if `ampRuntimeVersion` is specified. This ensures the self-hosted runtime version matches version of the dynamic component delivered by `cdn.ampproject.org`. |
There was a problem hiding this comment.
This option is only effective if
ampRuntimeVersionis specified. This ensures the self-hosted runtime version matches version of the dynamic component delivered bycdn.ampproject.org.
I don't understand why it only makes sense in conjunction with ampRuntime Version.
| * re-written. You can combine `ampRuntimeVersion` and `ampUrlPrefix` to rewrite | ||
| * AMP runtime URLs to versioned URLs on a different origin. | ||
| * | ||
| * rewriteDynamicComponents is only effective if `ampRuntimeVersion` and |
|
|
||
| // Should be kept up to date with dynamic components listed here: | ||
| // https://github.com/ampproject/amphtml/blob/master/spec/amp-cache-guidelines.md#guidelines-adding-a-new-cache-to-the-amp-ecosystem | ||
| const dynamicElements = ['amp-geo']; |
There was a problem hiding this comment.
please move this into a constant at the top of the file
There was a problem hiding this comment.
I added it to AMP_CONSTANTS. Good? Bad?
| // Should be kept up to date with dynamic components listed here: | ||
| // https://github.com/ampproject/amphtml/blob/master/spec/amp-cache-guidelines.md#guidelines-adding-a-new-cache-to-the-amp-ecosystem | ||
| const dynamicElements = ['amp-geo']; | ||
| const dynamicTemplates = []; |
There was a problem hiding this comment.
I added it to AMP_CONSTANTS. Good? Bad?
| while (node) { | ||
| if (node.tagName === 'script' && this._usesAmpCacheUrl(node.attribs.src)) { | ||
| node.attribs.src = this._replaceUrl(node.attribs.src, ampUrlPrefix); | ||
| const isDynamicComponent = |
There was a problem hiding this comment.
please extract this into a separate method for readability
There was a problem hiding this comment.
Let me know if commit 3354b6a does this adequately.
See here and my following comment: #515 (comment) |
|
Hah! Completely forgot about this 🤦♂️. It starts getting tricky. With the revised self-hosting behavior ( Hence, I'd favor making this independent of the runtime version. |
Not everyone who self-hosts the AMP runtime has the infrastructure to support dynamic components like amp-geo, ref: https://github.com/ampproject/amphtml/blob/master/spec/amp-cache-guidelines.md#guidelines-adding-a-new-cache-to-the-amp-ecosystem Introduce option rewriteDynamicComponents that prevents modification of dynamic component URLs that would otherwise have ampUrlPrefix substituted. Two relevant tests added: rewrites_host_but_not_dynamic_components_with_rtv rewrites_host_but_not_dynamic_components_without_rtv
…roject#518)" This reverts commit 81e525d. Do not allow "partial self-hosting". All AMP components should come from the same origin to ensure version locking support is maintained. An alternative solution for amp-geo is to fall back to an API request instead of requiring cache modification when amp-geo-0.1.js is served.
…roject#518)" This reverts commit 81e525d.
…roject#518)" This reverts commit 81e525d.
DEPENDS ON #517
Not everyone who self-hosts the AMP runtime has the infrastructure to
support dynamic components like
amp-geo, ref: AMP cache guidelines.Introduce option rewriteDynamicComponents that prevents modification of
dynamic component URLs that would otherwise have ampUrlPrefix
substituted.
Two relevant tests added:
Fixes #515