-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Separate url resolution for cache #730
Comments
Hi there! That's a valid point. I haven't used that option too much myself yet so I'd like to get the input of @hirasso who's been using it extensively in some of his projects. In the meantime, I'll just point you to the demo site for the Fragment Plugin that will be released along with swup 4 next week or so. Sounds like a good fit for your use case — it's meant for targeting smaller page fragments with custom transitions for filter interfaces, overlays, and such. swup 4 will also come with a |
@jorisnoo I've only ever used swup.on("transitionStart", () => {
const url = swup.getCurrentUrl();
if (url !== swup.resolveUrl(url)) {
swup.cache.remove(swup.resolveUrl(url));
}
}); This might work if navigating using the browsers back/forward buttons, but won't work when clicking on links, due to a limitation in swup@3, that will be fixed in v4. In swup3, import Swup, { Location } from 'swup';
const swup = new Swup();
function maybeClearCache(url) {
if (url !== swup.resolveUrl(url)) { // or some condition that makes sense for your case :)
console.log(url);
swup.cache.remove(swup.resolveUrl(url));
}
}
swup.on("clickLink", (e) => {
// get the correct URL from the link element instead of the browser for click on links:
const url = Location.fromElement(e.delegateTarget).url;
maybeClearCache(url);
});
swup.on("popState", (e) => {
maybeClearCache(swup.getCurrentUrl());
}); |
Alternatively, you could brute-force overwrite import Swup, { Location } from 'swup';
const swup = new Swup();
swup.cache.getCacheUrl = (urlToResolve) => {
const { url } = Location.fromUrl(urlToResolve);
return url;
}; Just keep in mind that this function is not part of the public API and therefor might change without notice. It will be renamed to |
Hi, and first of all thank you very much for the great work on this library! I've just discovered that there is going to be a v4 — very exciting!
Describe the problem
I'm currently using the
resolveUrl
option to disable swup for a set of pages, where i do my own transitions (only part of the content is replaced, the other part stays and is filtered based on the url). This works great, except that all these 'ignored' pages now share one entry in the cache — which is the expected behavior, but in my case leads to inconsistent content being rendered (always the content of the first page that was cached).Describe the proposed solution
My case could be solved by somehow allowing to ignore or overwrite the
resolveUrl
option in the cache module — or by allowing to only partially enable the cache, depending on the url pattern.Alternatives considered
I've tried to clear the cache for these urls after various swup events, but unfortunately keep running into the issue. Disabling the cache fully solves it; but it would of course be a bummer to go without this feature.
How important is this feature to you?
Thank you very much for your consideration and all your effort!
The text was updated successfully, but these errors were encountered: