/** * > [!NOTE] * > Install using `bunx shadcn@latest add @remix-utils/cache-assets`. * * > [!NOTE] * > This can only be run inside `entry.client`. * * This function lets you easily cache inside the [browser's Cache Storage](https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage) every JS file built by Remix. * * To use it, open your `entry.client` file and add this: * * ```ts * import { cacheAssets } from "remix-utils/cache-assets"; * * cacheAssets().catch((error) => { * // do something with the error, or not * }); * ``` * * The function receives an optional options object with two options: * * - `cacheName` is the name of the [Cache object](https://developer.mozilla.org/en-US/docs/Web/API/Cache) to use, the default value is `assets`. * - `buildPath` is the pathname prefix for all Remix built assets, the default value is `/build/` which is the default build path of Remix itself. * * It's important that if you changed your build path in `remix.config.js` you pass the same value to `cacheAssets` or it will not find your JS files. * * The `cacheName` can be left as is unless you're adding a Service Worker to your app and want to share the cache. * * ```ts * import { cacheAssets } from "remix-utils/cache-assets"; * * cacheAssests({ cacheName: "assets", buildPath: "/build/" }).catch((error) => { * // do something with the error, or not * }); * ``` * * @author [Sergio Xalambrí](https://sergiodxa.com) * @module Client/Cache Assets */ export interface CacheAssetsOptions { /** * The name of the cache to use inside the browser Cache Storage * @default "assets" */ cacheName?: string; /** * The path prefix for all build assets, if you used a subdomain ensure this * is only the pathname part. * @default "/build/" */ buildPath?: string; } /** * Caches all JS files built by Remix in a browser cache. * This will use the Remix manifest to determine which files to cache. * It will get every JS file, get all the already cached URLs, remove any * old file, and finally add the new files to the cache. * * **This can only be run inside entry.client** */ export declare function cacheAssets({ cacheName, buildPath, }?: CacheAssetsOptions): Promise;