Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31892 closed Cleanup/optimization (fixed)

Added release notes about removing "type" attribute from rendered <script>'s.

Reported by: Buky Owned by: Jon Dufresne
Component: Documentation Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Buky)

Hi,

For Django in 3.0 and before when Media is used (forms.widgets.py), the method render_js will produce:

<script type="text/javascript" src="file.js"></script>

but in Django 3.1 we get:

<script src="file.js"></script>

This change is uncovered in Django 3.1 release notes (https://docs.djangoproject.com/en/3.1/releases/3.1/). Does it a regression?

Media.render_js before Django 3.1:

def render_js(self):
        return [
            format_html(
                '<script type="text/javascript" src="{}"></script>',
                self.absolute_path(path)
            ) for path in self._js
        ]

Change History (9)

comment:1 by Buky, 4 years ago

Description: modified (diff)

comment:2 by Jon Dufresne, 4 years ago

This behavior intentionally changed in e703b93a656b78b9b444bb3a9980e305ed002a70 for ticket #31080. As noted in that ticket, specifying the default type is not recommend.

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

Omitted or a JavaScript MIME type: This indicates the script is JavaScript. The HTML5 specification urges authors to omit the attribute rather than provide a redundant MIME type.

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

Authors should omit the type attribute instead of redundantly setting it.

Beyond simply being different, how is this causing an issue in practice?

If there is no practical issue then I think we should stick with the smaller, simplified form recommended by upstream authorities.

comment:3 by Buky, 4 years ago

it's just breaking news tests in django-pipeline and I don't find any information about this in the release notes

Thank you for the quick answer, I will do what is necessary to update the package

comment:4 by Jon Dufresne, 4 years ago

Has patch: set

I'm open to including a mention in release notes. Here is a go at that: https://github.com/django/django/pull/13312

Let me know if that would have helped.

comment:5 by Buky, 4 years ago

Great idea. That will be useful for other packages who deal with statistics.

comment:6 by Buky, 4 years ago

Summary: [Regression][Widgets][Media] render_js[Undocumented][Widgets][Media] render_js

comment:7 by Mariusz Felisiak, 4 years ago

Component: FormsDocumentation
Owner: changed from nobody to Jon Dufresne
Status: newassigned
Summary: [Undocumented][Widgets][Media] render_jsAdded release notes about removing "type" attribute from rendered <script>'s.
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In dd5173ca:

Fixed #31892 -- Added backward incompatibility note about Media <script> tags changes.

Refs 31080.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In c5a80420:

[3.1.x] Fixed #31892 -- Added backward incompatibility note about Media <script> tags changes.

Refs 31080.

Backport of dd5173ca1b3e65f8664ad90b81cba032826991dc from master

Note: See TracTickets for help on using tickets.
Back to Top