question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecating cdn.ampproject.org/v0/validator.js in favor of WebAssembly version

See original GitHub issue

Summary

The AMPHTML Validator ensures that critical features of the AMPHTML spec are followed within AMP related documents. It is maintained by a set of rules and engines written in C++ and JavaScript that apply those rules during validation. There are many developer tools that utilize these validator engines to assist in the development of valid AMP documents.

Due to ongoing complexity and developer maintenance of two validator engines, the Caching Working Group is deprecating the native JavaScript validator in favor of a WebAssembly validator which uses the C++ engine.

Existing developer tools such as the Validator Web UI, Chrome Extension, VS Code Extension and Node.js Package have already migrated to the WebAssembly validator.

To inform existing developers using validator.js directly and not through one of these developer tools, the APIs in validator.js will be deprecated to return an error message to update tooling to use validator_wasm.js and it will no longer provide validation. This was released for a short time on Monday, September 13, 2021 before being rollbacked. It will be released again on Thursday, September 23, 2021 pending approval here.

Developers unable to migrate to the WebAssembly validator immediately due to compatibility issues, will be able to utilize a temporary fallback to the native JavaScript validator (validator.20211101.deprecated.js). This will be removed on November 1, 2021.

Motivation

The AMPHTML Validator has two implementations. One in C++ and one in JavaScript. These utilize different HTML parsers which at times can cause differences between validation results of documents. Over time these differences have been reduced. However, there is ongoing complexity and maintenance costs in keeping these two implementations in sync. With a WebAssembly validator version released, it is no longer necessary to continue to endure those costs by deprecating the native JavaScript version in favor of the WebAssembly version.

Impact on Existing Users

Developers utilizing validator.js directly from the Google AMP Cache will need to upgrade to using the WebAssembly version (validator_wasm.js). A temporary fallback version is provided until November 1, 2021.

Alternative Implementation

A temporary fallback version is provided until November 1, 2021 via https://cdn.ampproject.org/v0/validator.20211101.deprecated.js. Ideally they would upgrade to https://cdn.ampproject.org/v0/validator_wasm.js or utilize an existing developer tool such as the Node.js Package.

Additional Context

Example of messaging returned by the deprecated native JavaScript validator via Node.js Package:

$ amphtml-validator --validator.js minimum_valid_amp.html

minimum_valid_amp.html:1:0 The native JavaScript AMPHTML Validator (validator.js) has been turned down. If you are seeing this error, update your tooling to instead load the API compatible WebAssembly AMPHTML Validator (validator_wasm.js) instead.

Example of messaging returned by the deprecated native JavaScript validator via DevTools:

> amp.validator.validateString('test');

validator.js:7 ERROR: The native JavaScript AMPHTML Validator (validator.js) has been turned down. If you are seeing this error, update your tooling to instead load the API compatible WebAssembly AMPHTML Validator (validator_wasm.js) instead.

Notifications

/cc @ampproject/wg-approvers

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
kristoferbaxtercommented, Sep 27, 2021

Oh, that makes sense, thanks for the clarification.

@rsimha Not sure if this is on your radar, but wanted to make sure it was known.

1reaction
antiphotoncommented, Sep 22, 2021

The WebAssembly validator is not 100% backward compatible with the previous native JavaScript validator, the validator_wasm.js adds an async init function, which must be called before all other functions. The developers need to not only change the URL to validator_wasm.js, but also need to add the statement await amp.validator.init();.

The amp.validator.init is async function because the initialization of WebAssembly is async. However, the public APIs (for example amp.validator.validateString) of the previous native JavaScript validator are declared sync functions, hence it is not possible to make the initialization of WebAssembly to be inside of amp.validator.validateString, and we have to introduce the new amp.validator.init.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebAssembly - MDN Web Docs
Chrome Edge WebAssembly Full support. Chrome57. Toggle history Full support. Edge16. To... CompileError Full support. Chrome57. Toggle history Full support. Edge16. To... CompileError() constructor Full support....
Read more >
Summary - bytemeta
Deprecating cdn.ampproject.org/v0/validator.js in favor of WebAssembly version. ... the native JavaScript version in favor of the WebAssembly version.
Read more >
WebAssembly
WebAssembly describes a memory-safe, sandboxed execution environment that may even be implemented inside existing JavaScript virtual machines.
Read more >
WebAssembly | Can I use... Support tables for HTML5, CSS3, etc
1 Can be enabled via the javascript.options.wasm in about:config · 2 Can be enabled via the #enable-webassembly flag · 3 Can be enabled...
Read more >
WebAssembly - Wikipedia
WebAssembly (sometimes abbreviated Wasm) defines a portable binary-code format and a ... the most popular languages already have at least some level of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found