Remove redundant type="text/javascript" from <script> elements

In HTML5, <script> elements default to MIME type text/javascript. The
HTML5 living standard and MDN recommend against including the attribute.

From https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type

> The HTML5 specification urges authors to omit the attribute rather
> than provide a redundant MIME type.

From https://html.spec.whatwg.org/#the-script-element

> Authors should omit the type attribute instead of redundantly setting
> it.
This commit is contained in:
Jon Dufresne 2019-12-15 07:01:14 -08:00
parent cb5fab5db9
commit e6915baae8
12 changed files with 16 additions and 19 deletions

View File

@ -30,7 +30,7 @@
.related { display: none; }
{% endif %}
</style>
<script type="text/javascript">
<script>
// intelligent scrolling of the sidebar content
$(window).scroll(function() {
var sb = $('.sphinxsidebarwrapper');

View File

@ -91,7 +91,7 @@ Google Analytics
{%- block extrahead %}
{{ super() }}
<script type="text/javascript">
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XXX account number XXX']);
_gaq.push(['_trackPageview']);
@ -103,7 +103,7 @@ Google Analytics
<div class="footer">This page uses <a href="https://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
<script>
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ?
@ -134,7 +134,6 @@ Google Search
(function() {
var cx = '......';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];

View File

@ -146,7 +146,6 @@ class JavaScript(str):
self = str.__new__(cls, filename) # type: ignore
self.filename = filename
self.attributes = attributes
self.attributes.setdefault('type', 'text/javascript')
return self
@ -1136,7 +1135,6 @@ def setup_js_tag_helper(app: Sphinx, pagename: str, templatexname: str,
attrs.append('src="%s"' % pathto(js.filename, resource=True))
else:
# str value (old styled)
attrs.append('type="text/javascript"')
attrs.append('src="%s"' % pathto(js, resource=True))
return '<script %s>%s</script>' % (' '.join(attrs), body)

View File

@ -12,7 +12,7 @@
{% block extrahead %}
{{ super() }}
{% if not embedded and collapse_index %}
<script type="text/javascript">
<script>
DOCUMENTATION_OPTIONS.COLLAPSE_INDEX = true;
</script>
{% endif %}

View File

@ -87,7 +87,7 @@
{%- endmacro %}
{%- macro script() %}
<script type="text/javascript" id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
<script id="documentation_options" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/documentation_options.js', 1) }}"></script>
{%- for js in script_files %}
{{ js_tag(js) }}
{%- endfor %}

View File

@ -11,16 +11,16 @@
{% set title = _('Search') %}
{%- block scripts %}
{{ super() }}
<script type="text/javascript" src="{{ pathto('_static/searchtools.js', 1) }}"></script>
<script src="{{ pathto('_static/searchtools.js', 1) }}"></script>
{%- endblock %}
{% block extrahead %}
<script type="text/javascript" src="{{ pathto('searchindex.js', 1) }}" defer></script>
<script src="{{ pathto('searchindex.js', 1) }}" defer></script>
{{ super() }}
{% endblock %}
{% block body %}
<h1 id="search-documentation">{{ _('Search') }}</h1>
<div id="fallback" class="admonition warning">
<script type="text/javascript">$('#fallback').hide();</script>
<script>$('#fallback').hide();</script>
<p>
{% trans %}Please activate JavaScript to enable the search
functionality.{% endtrans %}

View File

@ -17,5 +17,5 @@
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
<script>$('#searchbox').show(0);</script>
{%- endif %}

View File

@ -11,7 +11,7 @@
{%- block scripts %}
{{ super() }}
<script type="text/javascript" src="{{ pathto('_static/bizstyle.js', 1) }}"></script>
<script src="{{ pathto('_static/bizstyle.js', 1) }}"></script>
{%- endblock %}
{# put the sidebar before the body #}
@ -26,6 +26,6 @@
{%- block extrahead %}
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!--[if lt IE 9]>
<script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
<script src="_static/css3-mediaqueries.js"></script>
<![endif]-->
{%- endblock %}

View File

@ -12,6 +12,6 @@
{%- block scripts %}
{{ super() }}
{% if theme_collapsiblesidebar|tobool %}
<script type="text/javascript" src="{{ pathto('_static/sidebar.js', 1) }}"></script>
<script src="{{ pathto('_static/sidebar.js', 1) }}"></script>
{% endif %}
{%- endblock %}

View File

@ -15,7 +15,7 @@
{%- endblock %}
{%- block scripts %}
{{ super() }}
<script type="text/javascript" src="{{ pathto('_static/theme_extras.js', 1) }}"></script>
<script src="{{ pathto('_static/theme_extras.js', 1) }}"></script>
{%- endblock %}
{# do not display relbars #}
{% block relbar1 %}{% endblock %}

View File

@ -1216,8 +1216,8 @@ def test_html_assets(app):
'href="https://example.com/custom.css" />' in content)
# html_js_files
assert '<script type="text/javascript" src="_static/js/custom.js"></script>' in content
assert ('<script async="async" type="text/javascript" src="https://example.com/script.js">'
assert '<script src="_static/js/custom.js"></script>' in content
assert ('<script async="async" src="https://example.com/script.js">'
'</script>' in content)

View File

@ -70,7 +70,7 @@ def test_mathjax_options(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').text()
assert ('<script async="async" integrity="sha384-0123456789" type="text/javascript" '
assert ('<script async="async" integrity="sha384-0123456789" '
'src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?'
'config=TeX-AMS-MML_HTMLorMML"></script>' in content)