Replies: 1 comment
-
Thanks for the proposal! Well, you can already do this with custom switches, e.g. const pjax = new Pjax({
selectors: [
// select the single head instead of the multiple meta.
'head',
],
switches: {
// define your own switch algorithm for head.
'head': (head, respHead) => {
// this example is for meta tags with a name.
const metas = [...head.getElementsByTagName('meta')].filter((meta) => !!meta.name);
const respMetas = [...respHead.getElementsByTagName('meta')].filter((meta) => !!meta.name);
metas.forEach((meta) => {
// we consider two meta tags the same if they has the same name.
const respIndex = respMetas.findIndex(({ name }) => name === meta.name);
if (respIndex >= 0) {
// 1. if a meta tag exists in both, update its value
meta.content = respMetas[respIndex].content;
respMetas.splice(respIndex, 1); // remove from the array so that it won't be appended later.
} else {
// 2. if a meta exists on the current dom but not in the response, remove it.
meta.remove();
}
});
// 3. if meta tag exists on the response but not on the current dom, add it.
head.append(...respMetas);
},
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my project one of the selectors i use is 'meta', this allow me to update important tags between requests, however the problem starts when a specific page have a dynamically added meta tag, for instance when using Google Analytics it will sometimes add an origin-trial meta tag to the head.
In this scenario the pjax request will always fallback to regular document request since the number of the meta tags at the current head and the response head doesn't match.
I propose to add a mechanism which will handle meta tags specifically and:
Beta Was this translation helpful? Give feedback.
All reactions