Skip to content

Commit 4aaa76e

Browse files
Added information on excluding files from the cache.
1 parent 9bb288b commit 4aaa76e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,40 @@ make an interop call back to the browser to trigger the app installation.
122122
}
123123
}
124124
```
125+
### Excluding files from the cache (WebAssembly projects)
126+
Due to the way Blazor WebAssembly projects build, some of the required properties we use to generate a PWA are not available until post-build.
127+
128+
So, to ensure a smooth customisation, we recommend using a custom **Target** in your csproj (or as a separate file which you include in the build process).
129+
130+
There are two **`Properties`** that you can customise to exclude files from the cache.
131+
132+
- **`ServiceWorkerPreCacheExcludeFiles`** - by default this will exclude any files under `dist\_content` and any files in `WWWRoot` that start with a dot.
133+
File patterns listed here will be evaluated after build and excluded from the Service Worker cache.
134+
This property is used in both **Debug** and **Release** builds.
135+
136+
137+
- **`ServiceWorkerPreCacheExcludeReleaseFiles`** - by default this will exclude any `.pdb` files. This property is only used if you are building in **Release** mode.
138+
139+
You can add extra files to these **`Properties`** by adding a custom target to your project
140+
141+
```
142+
<Target Name="PWACustomise" BeforeTargets="CreatePWA">
143+
<PropertyGroup>
144+
<ServiceWorkerPreCacheExcludeFiles>
145+
$(OutputPath)dist\_redist\**\*.*;
146+
</ServiceWorkerPreCacheExcludeFiles>
147+
</PropertyGroup>
148+
<Message Importance="high" Text="Removing: $(ServiceWorkerPreCacheExcludeFiles)"/>
149+
</Target>
150+
```
151+
152+
The `Name` can be anything you like, but is required by `MSBuild`.
153+
154+
`$(OutputPath)dist` is the path to the distribution folder for a **Blazor WebAssembly** build.
155+
156+
So, this example is excluding all files under the `_redist` folder from the Service Worker Cache.
157+
158+
125159

126160
## Roadmap
127161

0 commit comments

Comments
 (0)