Loading assets in a noscript element
-
31-05-2021 - |
سؤال
I expect the standard behavior would be to not load any assets in a <noscript>
element, and a quick cursory test in FF and Chrome proves this to be the case. However, are there any situations where assets (e.g. an image) in a <noscript>
element, would be loaded when scripts are enabled?
المحلول
According to W3 specifications:
The NOSCRIPT element allows authors to provide alternate content when a script is not executed. The content of a NOSCRIPT element should only be rendered by a script-aware user agent in the following cases: The user agent is configured not to evaluate scripts. The user agent doesn't support a scripting language invoked by a SCRIPT element earlier in the document. User agents that do not support client-side scripts must render this element's contents.
So I guess just like your testing proved: elements inside a <noscript>
section will not be rendered (i.e. downloaded as well) at all when the client supports <script>
elements.
I also just tested this on a page of mine that uses an image inside its <noscript>
part and neither Chrome, FF, Opera or the IE did show any interest in downloading the image.
نصائح أخرى
I guess it depends on precisely what you mean. Take this markup:
<!DOCTYPE html>
<html>
<head>
<title>Test Case</title>
</head>
<body>
<noscript id="ns">
</noscript>
<script>
var ns = document.getElementById("ns");
ns.innerHTML = "</noscript><img src='http://www.alohci.net/dummy'>";
</script>
</body>
</html>
In Firefox this will result in an <img>
element inside the <noscript>
element and the image referenced is fetched from the server.
Notes:
1. I've no idea why this happens.
2. Only Firefox appears to do this.
3. I can't imagine any use for this.