How I built currency conversion tooltips
nicolasbouliane.com
nicolasbouliane.com
We've found that NextJS's Incremental Static Regeneration[0] hits the sweet spot for when we have needed to do this. Specifying a regeneration time allows us to say 'this data can be at most X seconds old' but if thousands of users hit a URL at once only one request is made.
[0] https://nextjs.org/docs/basic-features/data-fetching/increme...
However server-side generation would mean that exchange rates are cached along with the page by Google and archive.org. An old version of the page would show old exchange rates.
I care a great deal about letting users consume the content even if the website goes down, either through archive.org, Google Cache, CloudFlare, Pocket or their own archives.
Particularly today when so many programmers accept re-implementation of systems primitives in higher level languages de jour, there exists a wry truth in the (admittedly somewhat condescending) adage:
Those who don't understand Unix are condemned to reinvent it, poorly. - Henry Spencer
This sounds like an old man with a hammer, reminiscing of times where every single problem was a nail. True, hammer works for the threaded wood screws somewhat, but the new engineers with their electric screwdrivers are more efficient and build sturdier things.
Even if you are hell-bent on doing stuff the Linux way why not propose a pair of Systemd service and timer? At least there will be logs. Cron is such an antiquated way of doing things.
:D
It'd be nice to add a `tabindex` value and add a `:focus` part to the tooltip CSS to make it appear for users navigating via their keyboard rather than mouse. If you look up 'accessible tooltips' there might be a few other tips.
And needing to mouse-over all the numbers would annoy me quickly. Here's the peanut gallery suggestion: just like many sites have a language dropdown, add a dropdown to select the secondary currenc(ies), and all monetary values would then be displayed as e.g. "€175 (£150.05, $182.02)"
Old answer: Excellent. That’s how it should be done. So many people seem to ignore things browsers already tell the server.
It's a hack in my book, but it's the best hack I could come up with.
And the relation between system and browser language is not always simple. For instance Safari on macOS doesn't (seem to) reflect all the system-configured languages, it just returns the primary (or whatever you configured for safari specifically).
So if you habitually configure your system in en (-US or -GB) then add your "mother culture" as secondary, won't work, you'll get USD or GBP which may mean nothing to your day-to-day.
> It's a hack in my book, but it's the best hack I could come up with.
Since it's your own site, why not add a `localStorage` override?
Obviously it requires additional work (a currency picker UI of some sort, and a way to get to it from the tooltip), but it should allow users to fix things up when the defaults are not right for them.
https://www.lloydatkinson.net/posts/2022/tiny-projects-curre...
Ouch, Brandenburg felt that one!
(Brandenburg is a federal state that is "known" for being quite rural and lacking all sorts of infrastructure...)