Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ideas to slim down the library

See original GitHub issue

First of all, thanks for the great library. It worked like a charm for me.

That said, i’ve noticed that the app is bigger than I expected it to be, around 12KB after gzip. Part of the problem is that svelte has spoiled me when it comes to the size of the bundles, if this was an angular or ember library I wouldn’t bat an eye at the size.

However, it couldn’t avoid notice that my 17kb gzipped app grew to 29kb app after adding svelte-i18n and ~20 translations, which is a 70% increase.

Just listing some low hanging fruit to make the library smaller, checking if you think it’s worth to pursue them. I might help actually.

  • Right now, the format store’s value is a function that has time, date, number, capital, title, upper and lower properties attached. Because of that, rollup cannot treeshake unused features. If functions for formatting dates, times and numbers were explicit exported, rollup could just remove the unused stuff (for instance, I only format messages and times, not dates nor numbers). Arguably, capital, title, upper and lower may not even belong in this library, but I can see how they are convenient.

  • Maybe getClientLocale could be something users also explicitly import if they care:

import { getClientLocale, init } from 'svelte-i18n';
  fallbackLocale: "en",
  initialLocale: getClientLocale({ navigator: true }),
  • Lastly, and this is the big one really, use intl-messageformat to compile translations during the build step. That library accounts for 4/5ths of the size of svelte-i18n. If we could compile ahead of time the translations, we could not ship the library at all. We’d have to assess if the compiled JS functions, once uglified, would be bigger than the equivalent strings using the ICU message format. I reckon that they would be slightly bigger, but probably still smaller than shipping the library unless you have thousands of translations the use plural/select or interpolations. And since we already have the functions we wouldn’t have to use memoize to cache the slow parsing process.

Are you interested in investigating any of the above? The last one fits very well with svelte’s compiler philosophy.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

cibernoxcommented, May 13, 2021

@hmaesta I recently released a library implementing some of this ideas:

It has an API that I think it’s almost 100% compatible with svelte-i18n. The docs say it’s for SvelteKit but it will work on any rollup-based svelte app. If shouldn’t occupy more than 2/3 kb after minification and compression.

I presented it on a lighting talk in svelte summit a few days ago:

hmaestacommented, Jun 8, 2021

This page has been open for 26 days in my computer as a pinned tab, just waiting for the time when I could try @cibernox’s approach. 😅

After a little struggle with Rollup, I was able to test it and save ~100 KB. 🎉

Thanks for the help. I hope it can be merged to this repository, since the name is more friendly and already have some audience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Librarian's Tips for Losing Weight Your Way | HuffPost Post 50
If your interest in nutrition is to lose weight, you will find a vast array of books on the library shelves that offer...
Read more >
24 Ways to Lose Weight Without Dieting - WebMD
WebMD has surprising weight loss tips to help you slim down without starving or following a complicated diet. Photos show each strategy at...
Read more >
How To Lose Weight In 1 Week – Simple Tips To Follow At ...
Here, we have listed a few simple tips to shed some pounds as quickly as ... Mindful eating and chewing well can help...
Read more >
How to Lose Weight and Keep It Off -
Use tools to track your progress. Smartphone apps, fitness trackers, or simply keeping a journal can help you keep track of the food...
Read more >
12 tips to help you lose weight - NHS
Eat high fibre foods. Foods containing lots of fibre can help keep you feeling full, which is perfect for losing weight. Fibre is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found