jquery-pjax
jquery-pjax copied to clipboard
problem scrollTo on popstate with maxCacheLength = 0
Hi,
When using maxCacheLength = 0 on popstate event, the page scrollTo before replace content. Is it possible to scroll after replace content ?
Thx
Hi! Good catch. This is a tricky problem.
When maxCacheLength
is 0, basically that means pjax cache is disabled. That means that on popstate, we won't be able to restore the old page content from cache, but rather that we'll have to re-fetch previous page contents from the server.
Also, on popstate we don't do any manual scrolling (scrollTo
is ignored). We expect the browser to restore previous scroll position. This works well if previous content is restored from cache. But, because we're re-fetching it as outlined above, the content will be injected into the page async, so the scroll position would sometimes be off, because of variable heights of different web documents.
I'm not sure what the solution would be. We could try keeping scroll positions of every page in state objects, then on popstate manually scroll to that stored position after asynchronously fetching the content.
it can be a solution.
I cant use cache because I have trouble with some javascript plugin as select2 on popstate event .
I cant use cache because I have trouble with some javascript plugin as select2 on popstate event .
What is the trouble? What is the plugin that misbehaves?
I found two plugins on my site that have a problem
select2 => https://select2.github.io/ wysibb => http://www.wysibb.com/
these plugins are changing dom structure
So because they're changing DOM structure (like most JS plugins), how did you find that they break with pjax?
So I have a javascript function (function ApplyPlugins) that applies my JS plugins on my new content from ajax request (on "end" event )
When I do popstate the content of the page is ok from cache but plugins (select2, wysibb ..) does not work, the only way I've found is to reapply plugins on cache content with my function ApplyPlugins .
But with this logiqueI i apply 2 times plugins (or more if i do back next back next ...).