Reputation: 117
I have DNN with skins. my head tag has runat="server" so I tried adding a tag inside the head tags as so
<script async defer src="https://maps.googleapis.com/maps/api/js?key=<%#GoogleAPIkey%>"></script>
in the code behind I set the var GoogleAPIkey in a property. the issue is it does not load the value.
I then tried adding the script tag in code behind as this
HtmlGenericControl jqueryInclude = new HtmlGenericControl("script");
jqueryInclude.Attributes.Add("type", "text/javascript");
jqueryInclude.Attributes.Add("async", "async");
jqueryInclude.Attributes.Add("defer", "defer");
jqueryInclude.Attributes.Add("src", "https://maps.googleapis.com/maps/api/js?key=" + GoogleAPIkey );
this method outputs the tag as
<script async="async" defer="defer" src="https://maps.googleapis.com/maps/api/js?key=xxx"></script>
is this valid syntax or do I need to persue a different method of writing it out - or perhaps even moving it out of the head tags.
Upvotes: 3
Views: 836
Reputation: 32511
The spec states that async
is a boolean attribute. As for how boolean attributes are specified:
The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
If the attribute is present, its value must either be the empty string or [...] the attribute's canonical name, with no leading or trailing whitespace.
Note: The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.
So technically, what matters is that the attribute exists, not what it's value is. This means you could use async="async"
.
Upvotes: 4