-
Notifications
You must be signed in to change notification settings - Fork 243
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
optimizer: Make dynamic component URL rewrites optional #518
Conversation
This is ready for review, with the caveat that it has been written with #517 as its base. |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option is only effective if
ampRuntimeVersion
is 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.
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.
This is resolved in commit 3354b6a.
* 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 |
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.
same as above
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.
This is resolved in commit 3354b6a.
} | ||
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please move this into a constant at the top of the file
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
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.
I added it to AMP_CONSTANTS. Good? Bad?
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.
even better
let node = head.firstChild; | ||
let referenceNode = findMetaViewport(head); | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please extract this into a separate method for readability
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.
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
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.
Thanks a lot!
…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