- AMP:Building Accelerated Mobile Pages
- Ruadhan O'Donoghue
- 521字
- 2021-07-08 10:04:01
AMP boilerplate validation errors
Let's quickly go through the errors related to the AMP boilerplate. Errors related to AMP boilerplate are usually reported as occurring at the end of the document, and usually begin with text: "The manadatory tag...", like in the following two messages:
news.html:2:0 The mandatory attribute '' is missing in tag 'html
for top-level html'. (see https://www.ampproject.org/docs/reference/spec#required-markup)
news.html:30:7 The mandatory tag 'html for top-level html' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup)
These two error messages relate to the opening HTML tag. One occurs at line 2, character 0, and the second occurs at line 30, character 7 (that is, the end of the document). We see at line 2, we have <html lang="en"> but we know that our AMP documents should start with <html > or <html amp>. So make this change and reload. This error should be resolved.
The next error is:
The mandatory tag 'link rel=canonical' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup)
We know how to fix this! Just add a canonical tag pointing to itself or its desktop counterpart:
<link rel="canonical" />
If you are using a local web server, then your canonical tag will look something like this:
<link rel="canonical" href="http://localhost/news.html" />
Next is:
The mandatory tag 'meta charset=utf-8' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup)
We can fix this too: Just add <meta charset="utf-8"> immediately after the opening <head> tag.
Next we have:
The mandatory tag 'meta name=viewport' is missing or incorrect. (see https://www.ampproject.org/docs/reference/spec#required-markup)
For this one, we need to add the following to our AMP page:
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
Then we have three related errors:
The mandatory tag 'noscript enclosure for boilerplate' is missing or incorrect.
The mandatory tag 'head > style[amp-boilerplate]' is missing or incorrect.
The mandatory tag 'noscript > style[amp-boilerplate]' is missing or incorrect.
We can take these three errors together since they are all caused by the same issue: the missing mandatory <style amp-boilerplate> tag. Add the following:
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
With each error you fix, hit reload and examine the developer console. You should see the list of errors getting smaller. Good work! You're making progress. So far, we've dealt only with the validation errors related to the mandatory AMP boilerplate code. You should only have the following validation errors remaining:
The tag 'script' is disallowed except in specific forms.
The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'?
The attribute 'href' in tag 'link rel=stylesheet for fonts' is set to the invalid value 'style.css'.
- INSTANT Mock Testing with PowerMock
- Spring 5.0 By Example
- iOS 9 Game Development Essentials
- Spring技術(shù)內(nèi)幕:深入解析Spring架構(gòu)與設(shè)計(jì)
- NLTK基礎(chǔ)教程:用NLTK和Python庫構(gòu)建機(jī)器學(xué)習(xí)應(yīng)用
- KnockoutJS Starter
- 利用Python進(jìn)行數(shù)據(jù)分析
- Frank Kane's Taming Big Data with Apache Spark and Python
- Statistical Application Development with R and Python(Second Edition)
- JavaScript應(yīng)用開發(fā)實(shí)踐指南
- CRYENGINE Game Development Blueprints
- JQuery風(fēng)暴:完美用戶體驗(yàn)
- Python GUI Programming Cookbook(Second Edition)
- 面向?qū)ο蟪绦蛟O(shè)計(jì)及C++(第3版)
- 嵌入式C編程實(shí)戰(zhàn)