Validate AMP Pages
The key strength of AMP isn’t just that it makes your pages fast, but that it makes your pages fast in a way that can be validated. This way, third parties such as Twitter, Instagram or Google Search can feel great about serving AMP pages to readers in increasingly interesting ways.
How do I check if my page is valid AMP?
The AMP validator comes bundled with the AMP JS library, so it is available on every AMP page out of the box. To validate:
- Open your page in your browser
- Add “
#development=1” to the URL, for example,http://localhost:8000/released.amp.html#development=1. - Open the Chrome DevTools console and check for validation errors.
What happens if my page isn’t valid?
The AMP validator isn’t just a convenience for you during development. It’s also used by platforms like Twitter or Google who integrate your AMP pages into their content and search results. More so, they usually don’t request the pages directly from your server but make use of the Google AMP Cache, a free service that caches your pages and makes them available across the world, so they load even faster.
If the AMP validation service detects that there’s something wrong with your page, it won’t get discovered and distributed by third party websites and won’t appear in the Google AMP Cache. So not only would you lose the speed benefits of the cache, it’s likely that your page will not be seen in many places! That would be a shame, so let’s make sure it doesn’t happen.
How do I fix validation errors?
Most validation errors are easy to address and fix. Consider this error:
- The first line of the error does its best to estimate where the error happened. Clicking on it should locate the general area.
- The second line, The part in red is the actual name of the error. In this case, MANDATORY_ATTR_MISSING signals that we’ve used a tag and forgot an important attribute.
- The third line points to the piece of the AMP HTML Spec that talks about the limitation or feature in question.
Carefully re-reading the spec, we realize that not only were we missing an important attribute, we also used a <script> tag for our own JavaScript, which isn’t allowed in the first place!
To better understand the complete list of potential errors, see the AMP Validation Errors guide. Each AMP specification also provides a validation errors table that lists the errors specific to that component. If you’re still stuck after careful evaluation, let us know and we’ll try to help.