Skip to content

Commit

Permalink
Use the custom attributes in a script tag
Browse files Browse the repository at this point in the history
Refer to Named modules / scripts whatwg#7600, proposed to use the custom attributes in a script tag rather to add another new <Name> tag to the Script which would be used as an alias that can be referred to in import statements. This will able to save bandwidth by reduce another new attribute.
  • Loading branch information
Shudi1234 authored Aug 9, 2022
1 parent 07f4b1d commit d7c4a41
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Contribution
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Name on Script Tags</title>
</head>
<body>
<script>
function display(msg) {
var p = document.createElement('p');
p.innerHTML = String(msg);
document.body.appendChild(p);
}
</script>
<script data-name="Name 1">
(function() {
var scripts = document.getElementsByTagName("script");
var info = scripts[scripts.length - 1].getAttribute("data-name");
display("Name '" + info + "'");
})();
</script>
<script data-name="Name 2">
(function() {
var scripts = document.getElementsByTagName("script");
var info = scripts[scripts.length - 1].getAttribute("data-name");
display("Name '" + info + "'");
})();
</script>
</body>
</html>

0 comments on commit d7c4a41

Please sign in to comment.