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

optimizer: Add meta tags for singleDoc self-host #622

Merged
merged 1 commit into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/optimizer/lib/transformers/RewriteAmpUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class RewriteAmpUrls {
}
node = node.nextSibling;
}

if (!this._usesAmpCacheUrl(host)) {
const versionlessHost = calculateHost({ampUrlPrefix: params.ampUrlPrefix});
referenceNode = this._addMeta(head, referenceNode, 'runtime-host', versionlessHost);
}
}

_usesAmpCacheUrl(url) {
Expand All @@ -93,6 +98,12 @@ class RewriteAmpUrls {
insertAfter(parent, preload, node);
return preload;
}

_addMeta(parent, node, name, content) {
const meta = createElement('meta', {name, content});
insertAfter(parent, meta, node);
return meta;
}
}

module.exports = RewriteAmpUrls;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8"><style amp-runtime i-amphtml-version="123456789000000">/* v0.css */</style>
<meta name="viewport" content="width=device-width,minimum-scale=1">
<link rel="preload" href="/amp/rtv/123456789000000/v0.js" as="script">
<meta name="runtime-host" content="/amp">
<script async src="/amp/rtv/123456789000000/v0.js"></script>
<script async custom-element="amp-experiment" src="/amp/rtv/123456789000000/v0/amp-experiment-0.1.js"></script>
<script async custom-element="amp-video" src="/amp/rtv/123456789000000/v0/amp-video-0.1.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link href="https://example.com/favicon.ico" rel="icon">
<link rel="preload" href="/amp/rtv/001515617716922/v0.js" as="script">
<link rel="preload" href="/amp/rtv/001515617716922/v0.css" as="style">
<meta name="runtime-host" content="/amp">
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link href="https://example.com/favicon.ico" rel="icon">
<link rel="preload" href="/amp/v0.js" as="script">
<link rel="preload" href="/amp/v0.css" as="style">
<meta name="runtime-host" content="/amp">
</head>
<body></body>
</html>