在 thymeleaf 中使用加速移动页面 (amp)

Using Accelerated Mobile Pages (amp) in thymeleaf

我需要在 (Spring MVC + thymeleaf) 网站的特定页面上使用 AMP 技术,遵循 Create Your First AMP Page

上的指南

验证器显示很多错误:

代码:

<!doctype html>
<html amp xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" lang="ar">
<head>
  <title>Some title</title>
  <meta charset="utf-8" />
  <meta content="IE=edge" http-equiv="X-UA-Compatible" />
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <link rel="canonical" content="some-url-here" />
  <style amp-boilerplate="">body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
  <script async="" src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
content is here
</body>
</html>

知道如何解决这个问题吗?

我发现最好的方法是实现一个不同的、轻量级的页面版本

例如:CNN已经引用了amp版本
查看本页来源: http://edition.cnn.com/2017/01/31/politics/donald-trump-supreme-court-announcement/index.html

这是放大器版本 https://amp.cnn.com/cnn/2017/01/31/politics/donald-trump-supreme-court-announcement/index.html

所以,对我来说,我将在不使用 thymeleaf 的情况下实现一个新页面

您可以毫无问题地使用 xmlns 标记,因为页面在没有这些标记的情况下会自行呈现。当您验证页面时,复制 html 以从您的浏览器进行验证,而不是从您的 IDE。使用 Chrome 右键单击​​ --> 查看页面源代码可为您提供干净的 html.