Asynchronous java script loading shows error

In asynchronous loading java script the following error is displayed:

The "async" attribute name associated with the "script" element type, followed by a '=' character. + jsf

I found this in my JSF2.4 application which uses the template.xhtml template file. 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:wiz="http://www.tolven.org/jsf/wizard"
xmlns:p="http://primefaces.org/ui"
xmlns:trim="http://www.tolven.org/jsf/trim">

      

This error occurs when I am using HTML 5 DOCTYPE, but it throws some other errors as no XHTML DTD was found.

So, I tried attribute async="async"

instead of just using async. Then all the errors were gone.

Is this the correct method to load a java script asynchronously in a context like this? Please let me know if you have any better ways to fix this.

+3


source to share


1 answer


As you can read here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script , "async" is an HTML5 attribute, so you have to use another way to load javascript asynchronously.

One trick might be to move your script just before the closing tag.



You can also use "require.js" as this answer suggests: Load async resource with requirejs timeout

+2


source







All Articles