defunkt / jquery-pjax

pushState + ajax = pjax
https://pjax.herokuapp.com
MIT License
16.73k stars 1.97k forks source link

Can't run a container cleanup before the cache snapshot #721

Open fredck opened 4 years ago

fredck commented 4 years ago

When integrating a component within a pjax enabled website, I have a strong need of cleaning up a few elements from the dom before pjax saves the current container snapshot.

At first, I though that the pjax:beforeReplace event was ideal for it - after all, "replace" can be understood like "remove the current one (take the snapshot) and inject the new one". It was too late.

Then, I thought about the pjax:start event... but for that, I went to check the source code:
https://github.com/defunkt/jquery-pjax/blob/153262eda33e31119eabb97cd5f14365580a3b35/jquery.pjax.js#L370-L371

Conclusion:

Q1 (proposal): shouldn't pjax:start happen somewhere earlier in the code?

Q2 (help!): how to safely tweak the dom before the snapshot is taken into the cache?