hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 30 forks source link

Implement a Service Worker integration? #9

Open L1lith opened 2 years ago

L1lith commented 2 years ago

I know this is probably out of the scope of this project, but there's one feature I think would be sweet which is service worker integration. Currently I am using next-pwa, but it doesn't really fulfill my needs. Here's basically the service worker I need (I am considering just coding my own custom worker, but it would be cool to see an integration here):

The worker needs to cache the entire website when I press the download button (kind of like next-offline, but I couldn't get it to work properly). The reason I am doing this is because I am deploying my site as a progressive web application, so that people with limited internet connectivity can get reliable access to the site. The problem is that if I deploy the website in a large number of languages that's going to skyrocket the download size, hence the need to download the entire site, but only in the language selected by the user. This is why I think there's a need for integration between service workers and next translation solutions.

I'm not sure if this would mean implementing an entirely custom service worker for this library, or potentially providing an integration with an existing solution like next-pwa. Either way this is just an idea and you're welcome to decide whether this falls inside of the scope you have for this project or not.

cvolant commented 2 years ago

I might consider this suggestion in a few months. But...

this.consider = async function () {
  try {
    let attempts = 0
    while (attempts < TOO_MUCH) {
      const result = await headache() // May take hours or days
      if (result && Math.random() > NEARLY_ONE) {
        return result
      }
      attempts++
    }
  } catch (error) {
    throw new Error(`Impossible: ${error.message}`)
  }
  throw new Error(`F**k`)
}