Comments (4)
thanks a lot for the detailed response and for pointing out the fragment plugin; very much appreciated. I'll happily look into all of this, maybe i'll even wait for the v4 release if it's imminent. Thank you both for your help and the work on the library!
from swup.
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 cache:set
hook you can use to update any cache items after they're created.
from swup.
@jorisnoo I've only ever used resolveUrl
for URLs that all returned the same data from the server. Basically like a mirror of the canonical link element. I guess you might have tried to clear the cache for your resolved URLs like this?
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, swup.getCurrentUrl()
called from inside transitionStart
returns the URL before the visit for clicks on links, but the URL after the visit during history visits. This will be more consistent in swup@4. Until then, you could work around this limitation by using two combined handlers:
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());
});
from swup.
Alternatively, you could brute-force overwrite swup.cache.getCacheUrl
to never resolve cache URLs:
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 swup.cache.resolve
in swup@4, for example.
from swup.
Related Issues (20)
- Update repo descriptions HOT 1
- Astro script doesn't work with Swup eventhough using Scripts Plugin
- Feature: Bundle logger HOT 2
- Allow navigation to current location HOT 3
- Export types for plugins HOT 8
- Re-activate Plugin Tests
- Allow bypassing cache for load and save HOT 2
- lighhouse score improvement
- URL Changes content keeps the same HOT 6
- contentReplaced and willReplaceContent being fired on the homepage
- Triggering link:click twice seems to interfere with content:replace and animation:in HOT 3
- Cannot use import outside of modules
- @swup/js-plugin: ^3.1.1 and @swup/scripts-plugin: ^2.0.0 break Astro formatting HOT 6
- Think about chances for optimizations when clicking a link during a visit HOT 9
- Suggest changes to this page links from the Documentation result in a 404 on GitHub HOT 1
- Rethink tests setup for official plugins HOT 5
- pageA goto pageB; but,with diffrent link style; when back to PageA,the links style is losted
- [Bug]: Undefined link href on Safari 13.1 and lower HOT 10
- [Feature Request]: Add way to easily listen to ALL hook events HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swup.