Problem/Motivation
If both modules big_pipe and prefetch_cache are turned on, then the prefetch caching would not work and an exception will be thrown, that the container is being serialized.
Prefetch cache caches the response object, which in the case of big pipe is BigPipeResponse. The class references some services, but doesn't include the DependencySerializationTrait. If we add the trait to the class, then it will be serialized properly, but now the response with the prefetch cache ID will be streamed. Thinking further it doesn't really make to use big pipe on prefetch cache requests, but there is no way for dynamically disabling big pipe on requests.
Proposed resolution
Make it possible through e.g. a query parameter to disable big pipe on requests.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2994348-6.with_comment_4.patch | 11.76 KB | mstiem |
| #7 | 2994348-6.test_adaption.patch | 10.43 KB | mstiem |
| #4 | 2994348-4.patch | 1.33 KB | hchonov |
Comments
Comment #2
hchonovComment #3
hchonovComment #4
hchonovComment #5
hchonovComment #6
tstoeckler@hchonov mentioned this needs a test, so marking accordingly.
The code in itself looks good to me, but I'm not in a position to give a proper thumbs-up/thumbs-down on this.
Comment #7
mstiem commentedI made some adaptions for the test BigPipeStrategyTest::testProcessPlaceholders here you will find the both patch files.
The one include the code from comment 4 and the other only the test class changes.
Comment #8
wim leersNote that https://www.drupal.org/project/big_pipe_demo already includes the ability to disable BigPipe on a per-request basis. See https://cgit.drupalcode.org/big_pipe_demo/tree/src/Render/Placeholder/Bi... and https://cgit.drupalcode.org/big_pipe_demo/tree/src/Plugin/Block/BigPipeO....
I'm not sure I fully agree with
(I think you meant to say "doesn't really make sense"?)
It indeed does not make sense to use JS-powered placeholder replacement. But I don't think there's a reason to do not have the server-side (no JS required) placeholder replacement? You don't gain anything, but you also don't lose anything.
I'm very hesitant to add this ability because before you know it, people are sharing links with BigPipe disabled, which A) is bad for performance, B) makes for atrocious URLs. Sensible URLs are holy on the web.
Looking at https://cgit.drupalcode.org/prefetch_cache/tree/js/prefetch_cache_proces..., I see two possible solutions:
placeholder_strategy.big_pipeservice: check if theprefetch_cache_request=1URL query arg is present, and if so, return early in::processPlaceholders().Finally: this is definitely not a bug, but a feature request, or task.
Comment #9
hchonovPrefetchCache doesn't put an url with that query parameter in the address bar. The only way this to happen will be if an user manually sets the query parameter.
It depends on how you see it :). Our main idea was that having prefetch cache on will retrieve the whole page without any additional loads, but with BigPipe on this will not happen even if there is enough time to process the response completely.
Additionally having a time between the requests might lead to mixed up data being shown to the user - old one served by PrefetchCache and newer one served by BigPipe, in which case I would say it is better to serve the whole page by PrefetchCache only.
Unfortunatelly we cannot trigger an AJAX request with custom set of cookies, but the document ones are being used by the AJAX request. In order to use the BigPipe no-JS cookie we have to set it on the document, which makes it available to all AJAX requests and not only to the prefetch cache requests. Do you think this is fine?
I guess this would be the best choice if you are totally against disabling big pipe through a query parameter. However this forces modules doing this to implement their own test coverage for ensuring BigPipe is being properly disabled. I personally would like to have such tests in the BigPipe module itself.
Comment #10
wim leersSearch engines will discover this URL in the HTML body, and hence it may end up in search results…
What do you mean? BigPipe also does not perform additional requests. That's a key reason it actually accelerates things, even on high-latency connections!
Can you clarify this? I don't understand this at all :(
Ah … I wasn't sure if this would be possible using
jQuery.ajax()(which is what your JS code uses). I guess it isn't possible then!I would be fine adding it to BigPipe if there are at least 2, preferably 3 use cases for it. So far, there's only one: this module. That's why for now I am opposed to adding this to Drupal core.
P.S.: For similar reasons, https://www.drupal.org/project/big_pipe_sessionless is a separate contrib module!
Comment #11
hchonovAn URL with that query parameter isn't contained in the HTML body neither :).
Oh right, I am sorry, I had something completely different in my mind.
You don't understand it, because it doesn't make any sense :D. I am sorry for the confusion.
Fair enough :). Then I'll give a try to the approach with the decorated service .. unless you know how we can process a BigPipe streamed response in PrefetchCache? I am not sure if this might work.
Comment #12
wim leersOh, hah! :D I'm glad we're on the same page then! (Pun intended :P)
I … did not realize you were implementing an alternative/extended variant of core's Page Cache! Why? Why isn't it enough to have JS prefetch those next pages, why do you also need them to be cached?
Comment #13
hchonovWell it is mostly because of our edit page, which is pretty heavy currently. It basically contains a lot of inline entity forms and therefore the FormBuilder and then the Renderer need quite some time to process it. So when a user goes to the view page, we start with the preparation of the edit page and when the user clicks on the edit link, then we simply return the already prepared response from the PrefetchCache. What we do isn't really caching, but prefetching and we do it also for resources which are uncacheable.
In order to make it much more seamless for the user, I've been considering not only to cache the response on the server side, but to return it and store it on the client side and simply exchange the current page through JS when the edit link is being clicked on.
I hope this makes the idea of the module more understandable :).
Comment #14
wim leersIt does! Thanks :)
Why isn't Dynamic Page Cache enough then? I'm willing to bet that DPC says it's an uncacheable response?
Right!
Idea: just request that next page in a hidden
<iframe>to ensure that everything is already primed in the browser anyway? The only difference would be that the server would need to re-generate that HTML response; nothing would change on the client compared to the current implementation of theprefetch_cachemodule.Comment #15
hchonovComment #16
wim leers#2994355: Prefetch cache doesn't work when BigPipe is enabled was fixed! That means we can close this.
I mean that if the
<iframe>requested it while the user was still on the current page, that'd only have primed the browser's caches for CSS/JS/images/videos/… If there's no server-side special caching going on, the HTML response would still need to be generated on the server and re-retrieved by the client (unless you work with e.g. a limited time max age, that might work!), but then at least the browser will still be able to render that next page much faster since all other assets are already cached. This would remove the need for any and all special server-side logic; it'd reduce the module to just a little bit of JS :)Comment #17
hchonov