﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28377	Retain order of form media assets during aggregation	Johannes Maron	info@…	"The order of static asset can matter, be it JavaScript code, that depends on jQuery or CSS files, that overwrite each other.
Currently Django does not retain the order specified in the ``Media`` property. When merging to Media objects, like widget and form media, unique entries only get amended which can change the order of assets.

Example:


{{{
>>> from django.forms import Media
>>> m1 = Media(js=('jQuery.js', 'script.js', 'noConflict.js'))
>>> m2 = Media(js=('jQuery.js', 'yet_another_script.js', 'noConflict.js'))
>>> print(m1 + m2)
<script type=""text/javascript"" src=""/static/jQuery.js""></script>
<script type=""text/javascript"" src=""/static/script.js""></script>
<script type=""text/javascript"" src=""/static/noConflict.js""></script>
<script type=""text/javascript"" src=""/static/yet_another_script.js""></script>
}}}

Here the very important order of assets for m2 has changed.

Using proper merging, the order can be maintained. Furthermore Django should warn developers, if two media classes have the same assets in a reversed order.

This is how the order should be:

{{{
>>> from django.forms import Media
>>> m1 = Media(js=('jQuery.js', 'script.js', 'noConflict.js'))
>>> m2 = Media(js=('jQuery.js', 'yet_another_script.js', 'noConflict.js'))
>>> print(m1 + m2)
<script type=""text/javascript"" src=""/static/jQuery.js""></script>
<script type=""text/javascript"" src=""/static/script.js""></script>
<script type=""text/javascript"" src=""/static/yet_another_script.js""></script>
<script type=""text/javascript"" src=""/static/noConflict.js""></script>
}}}

or

{{{
>>> from django.forms import Media
>>> m1 = Media(js=('jQuery.js', 'script.js', 'noConflict.js'))
>>> m2 = Media(js=('jQuery.js', 'yet_another_script.js', 'noConflict.js'))
>>> print(m1 + m2)
<script type=""text/javascript"" src=""/static/jQuery.js""></script>
<script type=""text/javascript"" src=""/static/yet_another_script.js""></script>
<script type=""text/javascript"" src=""/static/script.js""></script>
<script type=""text/javascript"" src=""/static/noConflict.js""></script>
}}}

Both cases have no duplicates and the order of both individual form media assets is preserved."	Cleanup/optimization	closed	Forms	1.11	Normal	fixed			Accepted	1	0	0	0	0	0
