javascript - 异步 java 脚本加载显示错误

标签 javascript html jsf-2 asynchronous-javascript

异步 ​​java 脚本加载显示以下错误:

Attribute name "async" associated with an element type "script" must be followed by the ' = ' character. + jsf

我在使用模板文件 template.xhtml 的 JSF2.4 应用程序中发现了这一点。 DOCTYPE 是

<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:p="http://primefaces.org/ui">

当我使用 HTML 5 DOCTYPE 时会出现此错误,但由于未找到 XHTML DTD,它会导致其他一些错误。

所以我尝试了属性 async="async" 而不是仅仅使用异步。 然后所有的错误都消失了。

在这样的上下文中,这是异步加载 java 脚本的正确方法吗?如果您有更好的方法来解决此问题,请告诉我。

最佳答案

如您所见https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script , "async"是一个 HTML5 属性,所以你必须使用另一种方式来异步加载你的 javascript。

一个技巧是将脚本移动到结束标记之前。

您也可以使用“require.js”,因为这个答案建议:Load async resource with requirejs timeout

关于javascript - 异步 java 脚本加载显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028329/

相关文章:

javascript - 不推荐使用 Vue 路由器 addRoutes,但我想向 Vue 路由器添加路由数组

php - PHP 中用户已存在或不存在的错误

html - 去除 &lt;input&gt; 框上的边框

php - 在 Javascript 中发送动态生成的图像作为 PHP 中的图像标题

javascript - 无法在 ejs 中设置未定义的属性 'round'

javascript - jquery ajax json 不返回 true

javascript - 如何将 Angular Material 图标资源路径与 Django 模板集成?

events - 如何防止 Richfaces 中的操作/事件重新加载页面?

java - Google App Engine 不解析 JSF 2.0 标签

java - 命令按钮不在 "enter"上提交,仅在 IE < 9 中按下