Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
javascript
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
7 Oct 2012 at 00:44 UTC
Updated:
6 Feb 2015 at 12:20 UTC
Jump to comment: Most recent
Comments
Comment #1
nod_I'm very curious to see if the tests pass :)
Comment #2
sunI'm afraid, I think this makes the situation even worse than it is now. :(
Cross-linking original issue:
#1805452: [meta] Asset library declarations, registry, usage, DX, compatibility, documentation
Comment #3
robloachIf you want your library to be presented after jQuery, then have it depend on jQuery. The "weight" is a hack around not having dependency information available. Now that it's in there, the "weight" doesn't need to persist. JavaScript is added in the correct order, in accordence to the dependency heirarchy.
Comment #4
sunNo. The reason for #2 is:
Libraries are processed and added to the page in no particular order.
This means that the effective "weight" and position of a particular library would critically depend on when exactly it was added — which really means: at which exact point its dependencies were resolved and the library itself was added. This is multidimensional, including the time and space continuum.
There is a unlimited amount of occasions in which #attached libraries may be processed and added to the page. Essentially, every single call to drupal_render() throughout the page rendering process. Removing weights means to introduce a hard dependency on a single process invocation for resolving all dependencies for all libraries that may be added to a response in single, central spot (involving a static variable), which is not only able to vertically resolve dependencies but also horizontally. (EDIT: Essentially, building and processing a Directed Acyclic Graph on every single request.)
I've mentioned this major problem space in #1787758: drupal_get_library() / hook_library_info() is not cached already, but earned nothing but pushback/ignorance.
Furthermore, such a process is almost guaranteed to produce always differing aggregates. Essentially killing the very last sense of aggregation and grouping logic we have/had. We're on a good way to destroy frontend performance entirely for D8. If that's the goal, keep on moving.
Comment #5
robloachA library's dependencies are added to the page before the library itself is added. If your project's dependencies are broken, then yes, there will be conflicts. But, if you define the dependencies correctly, then the order will be retained as defined by the hierarchy. If you provide the use case in which you're running into problems, then a link would be great.
That's unfortute. We should probably re-open that one.
Agreed... This is why I'm much more in favour of moving to RequireJS, where loading the dependencies is handled for us.
Otherwise, what solution do you suggest for weights?
Comment #6
sunTo understand what I mean, please create a test case:
1) Register 3 libraries A, B, C.
2) B depends on A, C depends on B.
3) Consecutively add all libraries A,B,C and confirm that dependencies are resolved correctly and files appear in the expected order.
4) Repeat with all possible permutations and confirm that the resulting order is always identical:
ABC
BCA
CAB
BAC
ACB
CBA
[5) See it fail.]
Comment #7
nod_Comment #8
sunAs far as I understood @sdboyer's plan for using Assetic, that will actually implement and resolve the problem that I mentioned in #4:
Instead of resolving partial dependencies individually for each library that is attached, a full graph of all libraries is built and resolved only once prior to the page being rendered out.
When I last looked at that patch though (a few days ago), it was still far away from being commit-ready. Therefore, I wonder whether we can implement an interim step and
drupal_get_library()blatantly ignore/remove custom weight options when parsing the definitions)Thoughts?
Comment #9
wim leersIs this a duplicate of #1945262: Replace custom weights with dependencies in library declarations; introduce "before" and "after" for conditional ordering?
Comment #10
robloachYup!