在 AMP html 中添加自定义 js 文件?

Adding custom js files in AMP html?

我想在我的 AMP 页面中添加自定义 javascript 插件,例如 owl-carousel 是否可以这样做?

AMP 页面不支持在页眉中加载 custom/external 脚本。它甚至不允许加载外部 stylesheets.

你可以参考他们的官方文档here。那说明

Scripts are Prohibited unless the type is application/ld+json. (Other non-executable values may be added as needed.) An exception is the mandatory script tag to load the AMP runtime and the script tags to load extended components

您不能在 AMP 中插入外部 javascript,因为 AMP 没有 javascript。但是使用 amp-iframe,您可以在 iframe 中创建功能并将该 iframe 包含在 AMP 页面中。

因此,如果您想使用 owl-carousel 显示图片,请创建一个 iframe,在其中使用 owl-carousel 实现图片轮播,并将该 iframe 包含在您的 AMP 页面中。所以它看起来就像只在 AMP 页面上。因此 iframe 将包含带有 owl-carousel.

的图片标签

但是,如果您想在 AMP 页面的轮播中显示图片,请访问 https://www.ampproject.org/docs/reference/components/amp-carousel 无论如何,这将帮助您在 AMP 中实现图像轮播。

如果您指定您的要求,我可以帮助您设计您的 iframe 或 amp-carousel,以可能的为准。

您不能在 AMP 中添加自定义 js 脚本,Javascript最好使用 AMP 组件。 AMP 有自己的轮播 amp-carousel

示例:Click Here