'Element script must not have attribute async unless attribute src is also specified or unless attribute type is specified with value module
i want to load some scripts on my page when the screen is more than 760 pixels, and otherd when it is less than 760 pixels etc
i would to find the faster solution for the page
i tried to use
<head>
<script id="script" async data-src="../myscript.js"></script>
</head>
<script>
function loadscript(){
let e = window.innerWidth;
if (e < 760) {
var script = document.querySelector("#script");
script.src = script.dataset.src;
}}
</script>
it work but the html validator dont like
is data-src reserved for images or can be used for scripts
i could use the document.createElement('script'); solution but i am not sure it's so fast to load the page
do you know what is the best solution? is it a problem to use data-src for a script?
thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
