Re: Non-blocking jQuery load
Johan Brichau <[email protected]>
| Newsgroups | gmane.comp.lang.smalltalk.squeak.seaside |
|---|---|
| Message-ID | <[email protected]> |
Joachim, On 20 Nov 2015, at 09:16, [email protected] wrote: The link does a show:, so the browser navigates away from the page the very instant the longest running ajax request is done. The dev toos in Firefox are cleared in that moment, so I cannot see anything of that "normal" request. While the two Ajax requests are being processed, I cannot see that "normal" request being sent to the server (but I should, even if the server doesn't react). The Chrome devtools have an option to “preserve log” in the network tab. This will not clear the tab on a page load. Seaside requires all requests for the same session to be processed sequentially. So, callbacks will not execute as long as the server is processing any other callback for the same session. So this explains a lot. This means we can cheat a little by showing the page earlier, but it won't be reacting to menu selections any sooner. Unless we do some "use another session (or even server) to collect the data" magic. The best solution for this is to fork a background process to collect the data in your component and only render the component when the data is present. Instead of using a ‘long running ajax request’ you poll the server with short requests until the data is ready and the component can be rendered. This is exactly what we do for tasks that take a long time to fetch data (e.g. rendering documents, long-running database queries, etc…). A spinner is shown on the webpage and the server is polled at seconds intervals until it effectively returns a rendered component. The data for that component is generated by a background process. This perfectly fits your decoration implementation. Something along these lines (disclaimer: untested code written in email client :) : replaced ifTrue: [div with: [self renderNextOn: html]] ifFalse: [ html document addLoadScript: (self loadScriptOn: html). div with: [ html image src: someSpinnerImage html space; text: self message]] loadScriptOn: html (html jQuery: self idSelector) load html: [:r | self isDataReady ifTrue:[ replaced := true. self renderNextOn: html] ifFalse: [ r addLoadScript: (self loadScriptOn: r) ]). Of course, this is a very simple and naive implementation and you might want to add more features to the decorator code (such as a limit to the number of retries, or handling errors, etc…). But I think you get the basic idea. Hope this helps! Johan _______________________________________________ seaside mailing list [email protected] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside