s00d / nuxt-i18n-micro

Nuxt I18n Micro is a fast, simple, and lightweight internationalization (i18n) module for Nuxt
https://s00d.github.io/nuxt-i18n-micro/
MIT License
87 stars 11 forks source link

Memory clogging when the route regex is big #39

Closed Rigo-m closed 4 weeks ago

Rigo-m commented 1 month ago

image

Vue-router tokenizer can be very slow when tokenizing complex regexes in the route matcher. Although this is more of a vue-router issue than a nuxt-i18n-micro issue, I was wondering if there was a faster implementation for the localized route (e.g.: checking the correct parameter via a route middleware).

The image above stems from a real-life project, with 70ish locales (en-us, en-gb, it-it etc).

Will try to provide a minimal reproduction, opening the issue to start a discourse

s00d commented 1 month ago

There is an option not to add all locales to the regular expressions. Instead, the module can create a single common regular expression and, when navigating to a page, simply check the locale using a plugin. In theory, this should significantly reduce the routing complexity.

example: /:locale([a-zA-Z-_]{2,2})/subpage

If you can provide a simple example and instructions for testing, I will be able to evaluate the difference in approaches.

Rigo-m commented 1 month ago

How can I help you with this?

s00d commented 1 month ago

How can I help you with this?

need make simple example and instructions for testing

Rigo-m commented 1 month ago

I have a super simple solution in mind, will provide a PR

s00d commented 1 month ago

I suggest testing the new version, and if everything is fine, we can close the issue.