Imagine a website with >100k daily visitors using any platform worldwide... As part of the design you need to show the country flag, prepending some information (product origin, phone number, office/shop/warehouse location, etc.)
What is the best way to do this and to keep users (e.g. Lighthouse score) and developers (proud of their results) happy at the same time?
Note, we can adapt any solution to our stack, just curious what is the best choice which can be done without benchmarking and why it is so? Typically, we can have a dozen of flags visible. However, if we have a product from a new country, it should be not that hard to extend the flag set...
Few options that can be used (for ease of comparison I stick to 16px flag width, for devs it would be nice to have an option inserting needed height. There are also a number of flags with complex graphics, I've checked KZ for example) :
- *.png sprite with CSS selector rules ~(50kB png + 10kB css) for 16px height
- *.png sprite with JS selector ~27kB png for 16px + 0.5kB JS(before minification and compression)
- React way ~1.3MB bundle, uses svg inline. However, e.g. kz.svg is ~10kB - is it optimized somehow for 16px width in production?
- Vue way kz.svg is optimized to be and icon ~1kB.
- Bootstrap way kz flag looks good enough
- Emoji way just few bytes for any flag, may look a bit different on different platforms. Seems to need a fallback solution for MS Windows
- For svg solutions you might also want to consider SVGO minification of svg images
- Lazy-loading is already implemented and can be used if needed.
- Not sure, but the best way may depend on if we use SPA, PWA, SSG, SSR, etc.