This week, Google announced that custom JavaScript can now be added to AMP pages. The amp-scriptcomponent can be used to enable user interactions, and to share code across AMP-enabled and non-AMP pages.

JavaScript features, such as multi-page forms that need to be validated before moving on to the next section, can now be delivered via AMP. Source: Google.

According to the AMP team, this was one of the most requested features from developers using AMP. It means that web pages delivered via AMP to incorporate more of the interactivity features that JavaScript offers.

The amp-script component runs a page’s custom JavaScript in a separate Worker thread.

Before this update happened, AMP pages have, for the most part, been static, which limited its uses and forced publishers to compromise features for speed and potentially visibility in mobile search results.

The new amp-script component is compatible with React, Preact, Angular, Vue.js, jQuery and D3.js frameworks.

amp-script won’t change page content without user interaction, so it won’t modify your content upon page load.

The script within a single amp-script must be less than 150kB.

Not all APIs are supported inside a Web Worker; refer to WorkerDOM’s list of allowed APIs.

SourceGeorge Nguyen