Response.include_files changes the order of the included files

38 views
Skip to first unread message

Leonel Câmara

unread,
Aug 8, 2017, 10:02:54 AM8/8/17
to web2py-developers
While trying to fix

I found something interesting. Response.include_files changes the order of the included files.  

Not only it changes the order. We expect it to do it according to our current tests:


I find this a serious problem as it can break javascript code, it can change the end style that takes precedence in CSS, it is in a word incorrect.

minify itself is also broken as it minifies everything that is not external to the application without a care that it may need to be interleaved with external sources.

Any suggestion on how to fix it?

Massimo DiPierro

unread,
Aug 8, 2017, 10:10:56 AM8/8/17
to web2py-d...@googlegroups.com
It should not. How does it happen. It is a list, not a dict. We simply loop over the list items.

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Aug 8, 2017, 10:18:40 AM8/8/17
to web2py-d...@googlegroups.com
If you look at include_files code, it loops trough the included files to separate it in 2 lists, one of internal files and another of external files. Then it may or may not minify the internal files, finally it extends the internal files list with the external files list and that's the final list.

By doing so it moves all the external files to the end causing them to be included last independently of where they started.

What should also happen when optimize_js or optimize_css is given is that internal files are minified and are only concatified if they are adjacent in the original list.  

Massimo DiPierro

unread,
Aug 8, 2017, 10:46:56 AM8/8/17
to web2py-d...@googlegroups.com
I see the complication here. I guess we should optimize each one in the order they appear but we cannot concatenate  them unless we also download those form the internet.

On Aug 8, 2017, at 9:18 AM, Leonel Câmara <leonel...@gmail.com> wrote:

If you look at include_files code, it loops trough the included files to separate it in 2 lists, one of internal files and another of external files. Then it may or may not minify the internal files, finally it extends in internal files list with the external files list and that's the final list.

By doing so it moves all the external files to the end causing them to be included last independently of where they started.

What should also happen when optimize_js or optimize_css is given is that internal files are minified and are only concatified if they are adjacent in the original list.  

Leonel Câmara

unread,
Aug 8, 2017, 8:13:00 PM8/8/17
to web2py-developers
I made a pull request with a possible solution to this problem:

https://github.com/web2py/web2py/pull/1731

My strategy here was to only concatenate/minify consecutive and internal to the application files.

This means that if the user appends some files, then an external file, then another internal file. He will end up with 2 compressed files. There's no way around this that I see apart from actually fetching the external files.
Reply all
Reply to author
Forward
0 new messages