So I've had this problem for a while now and thought it was related to the dialog module. But I just recently found out that turning off CDN makes it go away...
If I ajax-load anything that has an attached js or library, it usually doesn't work. So I usually have to load whatever required javascript on the original page for it to work. I'll provide an example...
Steps to reproduce:
- disable cdn
- ajax-load a node form that needs misc/tabledrag.js (for example, a node form with a field collection in it - it might fail with a multiple-value text field too). Note that the tabledrag works.
- enable cdn and repeat the previous step. Note that the tabledrag doesn't work.
- manually attach 'misc/tabledrag.js' on the original page (before the ajax load) and try the ajax-load again. Note that the tabledrag again works.
My setup:
CDN (latest dev) using origin pull and farfuture expiration
AdvAgg
bootstrap theme pulling bootstrap files from bootstrap's CDN
jquery update (2.1)
With all the aggregation going on, I don't know how I can debug this. Has anyone else seen this?
Comment | File | Size | Author |
---|---|---|---|
#14 | cdn-ajaxcall-nocdn.png | 47.65 KB | captainack |
#14 | cdn-ajaxcall-cdn.png | 47.34 KB | captainack |
#3 | cdnajaxissues.png | 86.88 KB | captainack |
Comments
Comment #2
Wim LeersThis is why the CDN module blacklists JS files by default. The reason: the same-origin policy.
Comment #3
captainack CreditAttribution: captainack commentedHi Wim.
Thanks for taking the time to reply so quickly!
I don't understand why this is a same-origin problem though. I don't get any 403's, and I thought that the CDN module already has this solved with the headers sent to (in my case) amazon.
Also I don't have any problems with normal page loads getting whatever they need from cloudfront. Also, post-ajax-request, I do have succesful hits to cloudfront (image attached showing this).
Is there something different about an ajax request that I'm not thinking about?
Thanks!
Comment #4
captainack CreditAttribution: captainack commentedOkay so I looked through the js and css files that DID get downloaded and tried to compare against the render array to try to find a pattern...
I'm not 100% positive, but it looks like there's a pattern!
- The files that ARE NOT working are attached as a "library"
- The files that ARE working are attached either as "css" or as "js".
I attached any libraries that are needed by the ajax call to the original page, and it seems to work around it.
In light of this new information, I'm tempted to switch this back to bug-report, since I don't see anything in the docs relating to library attachments vs css/js. But I don't want to be rude ;-).
Comment #5
captainack CreditAttribution: captainack commentedAlthough I've already worked around this, this has been a thorn for me, so I'm still digging...
It looks like there's another pattern:
Files that DO NOT work are also all either augmented or replaced via the bootstrap theme's _js_alter hook.
This seems to be a more likely suspect, since looking through the code seems like the library thing shouldn't make a damn bit of difference.
Comment #6
captainack CreditAttribution: captainack commentedSigh. Couldn't find the cause yet.
Okay I gotta give up on this for now. Maybe I'll be able to probe further later. For now I'm just working around it.
Comment #7
Wim LeersIt sounds like this is indeed not related to same-origin policy. I just saw all the trigger words in the issue summary :)
This then very much sounds like a Bootstrap-theme-induced problem. Can you disable that theme for a moment (or at least its alter hook) and see what difference that makes?
So far, everything indicates this is a problem in Bootstrap. The CDN module doesn't do anything special to libraries. As you can see, I also still reply to support requests. As long as something isn't a confirmed bug in the CDN module, I keep it as a support request, to make it clearer how many actual bugs there are.
Comment #8
captainack CreditAttribution: captainack commentedLol! I wish I'd thought of that before spending an hour or two digging through code! I'll try that as soon as I'm in the context of chasing this down again. I actually had no idea that the bootstrap theme swaps out and adds to some of the core javascript files. At least I learned that in the process.
And yes, I agree - this looks like something non-CDN-friendly that the bootstrap theme is doing. And thank you again for taking the time to help!
Comment #9
Wim LeersYou're welcome :)
Comment #10
Wim LeersDo you have news?
Comment #11
captainack CreditAttribution: captainack commentedSorry Wim. None yet. I got sucked into a hundred other things on the project. I forgot about this because I had the workaround of pre-loading the javascript :(.
But thanks for the reminder. I'll try to look into it again as soon as I can.
Comment #12
Wim LeersNo problem :)
Comment #13
captainack CreditAttribution: captainack commentedSorry it took so long.
I tried the following:
- Switched the theme back to Bartik
- Switched jquery update to the drupal default
- Disabled advanced aggregation
...and I still see the behavior:
unless I add the following to the render array of the original page:
...ajax-loaded tabledrags (e.g. field collections) don't show up properly (they show raw weights instead of the tabledrag).
When disabling CDN, it's not necessary to brute-force load those on the original page.
It looks like I read us up the wrong tree with the bootstrap stuff :(. But at least we eliminated those things.
When it's failing, I look at the javascripts being downloaded upon the ajax call, and I do see the tabledrag stuff being downloaded. So it's weird that it's not working.
Comment #14
captainack CreditAttribution: captainack commentedSo I took everything back to my production state and pasted a couple screenshots of the network tab (this time Edge's). The files fetched are exactly the same size in the CDN and no-CDN cases. The only difference there is the "initiator" column - in one case it says XMLHttpRequest and in the other it says "script". Not sure why.
Both cases have no errors on the console when you hit the ajax call. This is absolutely bizarre.
Comment #15
Wim Leers#14: Looks like you've found a browser bug :) Perhaps the label ("script" or "XMLHttpRequest") depends in part whether the requested asset has the same domain name as the website in question.
#13: Can you still reproduce that? I've got the feeling this was a browser bug, and that the browser updates in the past 2 months fixed it.
Comment #16
Wim LeersSorry for not thinking of this sooner. But the same problem was reported years ago: #1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS. The root cause is Drupal's AJAX system.
Comment #17
Wim Leers