This is a fork of the quicktabs issue: #1172010: Quicktabs, AdvAgg - Loaded via AJAX do not pull advagg bundles.
In this case, I'm using views3 with a block and have ajax enabled in the view. The view has a pager, so clicks on page 2/3/whatever are ajax calls. What happens is that the stuff coming back from views sends back all sorts of non-aggregated css and js files. This causes both theming and JS issues when the javascript is inserted for a second or third time.
Here's what I see.
1) Click page 2 on a pager for the view, and you do this:
/views/ajax?js=1&page=1&view_name=view_wall&view_display_id=block_2&view_args=&view_path=node&view_base_path=null&view_dom_id=1&pager_element=0
2) In views, looking at views.module, the callback for /views/ajax is the views_ajax() function in includes/ajax.inc. OK, heading over to that function you can see it construct a $object before it sends it off to views_ajax_render() at the very bottom of the function. There are two things to note here.
$object->scripts at this point has a big list of unaggregated javascript files, and $object->css has a big list of unaggregated css files. This seems to be what gets returned to the client's ajax request.
This seems to be what's creating the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | ajax_load-1193578-9.patch | 5.58 KB | markus_petrux |
| #2 | 1193578-2.patch | 2.48 KB | rjbrown99 |
Comments
Comment #1
rjbrown99 commentedIt looks like scripts and css are inserted during the drupal_alter:
I grepped around, and voila, the alter is called in the ajax_load module. This is a prerequisite of another module I use (editablefields), which is why I have it on the site in the first place. They do an ajax_load_ajax_data_alter(&$data) and pop in scripts and css files.
I changed the title of this issue appropriately.
Might be a very similar patch to the quicktabs fix, at least quick+dirty. Maybe you want to make that a callable function or hook in advagg to return the js+css files on a page? Then you can centralize the code for it and just call one function from support modules.
Comment #2
rjbrown99 commentedHere's a patch for ajax_load, release version 1.3. Based on the patch here: #1172010: Quicktabs, AdvAgg - Loaded via AJAX do not pull advagg bundles. I'm leaving this in advagg until mikeytown2 sees it, then please punt it to the ajax_load issue queue. I figure you might want to update the 'known issues' page.
This fixes my issue completely btw, no more multiple css or js file loads at all.
Comment #3
mikeytown2 commentedPatch looks good, moving to http://drupal.org/project/ajax_load
Comment #4
mikeytown2 commentedComment #5
rjbrown99 commentedI thought about this some more, and it could probably be done via advagg if that was an option. Set the module priority higher than ajax_load, call the same views hook, and check to see if the $object->scripts and $object->css were present. If so, rework them appropriately and send back to views.
Comment #6
markus_petrux commentedRather than adding support for more modules that alter the normal flow of stylesheets added to the page, it seems to me there may be one way to cover all cases, or at least I'm thinking on a solution in that direction.
It seems to me all these modules have in common than implement a page preprocess function where they alter the list of js/css files. So maybe we can replicate this pattern from
ajax_data_get_data(). ie. emmulate a theme(page) is being processed, so that all page preprocess funcions are invoked, and then we can get the js/css after that.Comment #7
rjbrown99 commentedSounds like a decent approach. I might be more inclined to like my idea in #5 - at least for advagg support, set that module weight to be relatively high, and then work with whatever comes back. That way ajax load and anything else that manipulates data with the views hook can do whatever magic they want and still have their js+css aggregated.
miketown2 what say ye?
Comment #8
mikeytown2 commentedEmulating a page request will work, just seems a bit heavy. You will have to parse the html and extract the css & js from it. Copying what the CDN module does in fallback mode would work though.
The one advantage advagg brings to the table is the fact that you can create an array of css/js files and build a custom bundle that contains just the missing files. With emulation you won't get that fine level of control over the files sent back. Also for D6 I don't see another alt to advagg showing up any time soon.
All of this being said, its a toss up in my opinion. Either way is a go.
Comment #9
markus_petrux commentedWell, yes, we have to parse the markup to extract js/css files, but maybe it can be done.
Attached a patch on a start on this direction. Please, let me know how it works. Variations on this to be more compatible with more cases are more than welcome.
Comment #10
markus_petrux commentedWell, we've been testing the patch internally, and it seems to do the job well. We do not use advagg, however. I'll apply the patch to -dev to make it easy to test. Feedback is welcome. Thanks. :)
Comment #11
markus_petrux commentedBetter title. I'm about to apply the patch in #9. Hopefully that can help obtain more feedback on this approach.
Comment #12
markus_petrux commentedPatch in #9 applied:
- http://drupalcode.org/project/ajax_load.git/commit/3e52e29
For the moment, this is the only change in -dev package, so it's easy to choose which version to try out.
Thanks
Comment #13
tibip commentedAfter upgrading to latest dev from August 30, I cannot see messages set with drupal_set_message anymore. I suspect this change right here caused that, because the emulation of theme(page) also unsets $_SESSION['messages'] and on the actual theme(page), running the second time, the messages list end up empty.
Comment #15
markus_petrux commentedOh, I missed #13. Also, we should not invoke our own preprocess page template callback when emulating theme('page').
Re-opening... fix coming...
Comment #16
markus_petrux commentedBoth issues should be fixed in the repository:
- http://drupal.org/commitlog/commit/5730/081711f550dbe705fda3c9838604ebce...
Comment #17
rjbrown99 commentedFWIW, I have not yet tested the updated code. I may over the next few days. Seems like this was committed to the 1.x branch, I take it that's the current direction vs the 2.x?
Comment #19
jason.fisher commentedUsing the latest dev of both advagg and ajax_load and still having problems.
ajax_load is successfully adding CSS/JS files, but it is adding CSS/JS to a page even if it is already on the page. This doubling-up is causing CSS and JS errors. Perhaps this is related to the ctools advagg issue?