好的,我遇到了同样的问题,对我来说最好的方法是使用 iframe,它会异步渲染。这确实意味着,您可以像这样解决它:
服务器端 api:
GET 请求(例如/api/frames/my-js-script-app)。调用后,您将获得以下代码:
<html>
<head>
<script defer src="your_js_scripts"></script>
</head>
<body>
<!-- html code which using your javascript, if exists... --!>
</body>
</html>
将 AMP 框架库添加到您的应用程序:
<head>
...
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
</head>
现在,您可以在您的身体中使用:
<amp-iframe width=500 height=300
sandbox="allow-scripts allow-same-origin"
layout="responsive"
frameborder="0"
src="https://localhost/api/frames/my-js-script-app">
</amp-iframe>
在您的服务器上创建 api 时要小心。AMP 框架需要https通信 - 它的意思是这样的:https://localhost/api/frames/my-js-script-app
现在,amp 将异步渲染您的应用程序,每个人都很高兴:-))
希望能帮助到你!