You can achieve this by using a combination of cache strategies in your Service Worker. One way to do this is to implement a "network first" strategy, where the Service Worker first attempts to fetch the resource from the network, and if it fails (i.e. the device is offline), it falls back to the cached version.

To implement this strategy, you can use the "fetch" event in your Service Worker to intercept all network requests. You can then use the "fetch" API to attempt to fetch the resource from the network. If the fetch is successful, you can update the cache with the new version of the resource and return the response to the page. If the fetch fails (i.e. the device is offline), you can use the "caches.match" API to check if the resource is already cached, and return the cached version to the page.

Here's an example of how you can implement a "network first" strategy in your Service Worker:

```
self.addEventListener('fetch', event => {
  event.respondWith(
    fetch(event.request)
      .then(response => {
        // Clone the response to update the cache
        const clonedResponse = response.clone();

        // Update the cache with the new version of the resource
        caches.open('my-cache')
          .then(cache => cache.put(event.request, clonedResponse));

        // Return the response to the page
        return response;
      })
      .catch(() => {
        // Attempt to fetch the resource from the cache
        return caches.match(event.request);
      })
  );
});
```

In this example, the Service Worker first attempts to fetch the resource from the network using the "fetch" API. If the fetch is successful, the Service Worker updates the cache with the new version of the resource and returns the response to the page. If the fetch fails (i.e. the device is offline), the Service Worker uses the "caches.match" API to check if the resource is already cached, and returns the cached version to the page.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence