You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+27-12Lines changed: 27 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,9 @@ Just add this package and tell it which routes (page, css, js, etc.) to process.
24
24
25
25
AspNetStatic works equally well with Blazor (SSR), Razor Pages, and MVC (controllers + views).
26
26
27
-
> :bulb: Blazor pages must not rely on any client-side (JS, WASM) functionality for rendering, or any behaviors like showing a placeholder (e.g. a spinner) before rendering the actual content.
27
+
<!-- :bulb: -->
28
+
> [!Important]
29
+
> Blazor pages must not rely on any client-side (JS, WASM) functionality for rendering, or any behaviors like showing a placeholder (e.g. a spinner) before rendering the actual content.
28
30
> The rule-of-thumb (for any tech you want to use with AspNetStatic) is that as long as the content has completed rendering by the time AspNetStatic receives it (via http request), then it will work fine.
29
31
30
32
#### But wait, there's more!
@@ -120,12 +122,15 @@ Keep the following in mind when specifying routes in the `IStaticResourcesInfoPr
120
122
- You can skip content optimization<sup>1</sup> or choose a specific optimization type for routes you add to the `PageResources` collection (see `OptimizationType` property). The default optimization type setting, `OptimizationType.Auto`, automatically applies the appropriate optimization.
121
123
- You can set the encoding for content written to output files for routes you add to the `PageResources` collection (see `OutputEncoding` property). Default is UTF8.
122
124
123
-
> :bulb: All of the above also applies to routes for CSS, JavaScript, and binary (e.g. image) files specified in the `OtherResources` collection property.
124
-
125
+
> [!Note]
125
126
> 1: Content optimization options apply only when content optimization is enabled. Please see the __Content Optimization__ section below for details.
126
127
128
+
> [!Tip]
129
+
> All of the above also applies to routes for CSS, JavaScript, and binary (e.g. image) files specified in the `OtherResources` collection property.
130
+
127
131
### Routes vs. Generated Static Files (page resources)
> :bulb: The same rules apply when links in static files are updated to refer to other generated static pages.
197
-
203
+
> [!Tip]
204
+
> The same rules apply when links in static files are updated to refer to other generated static pages.
198
205
199
-
__IMPORTANT NOTE__: In ASP.NET Core, UrlHelper (and the asp-* tag helpers) generate link URIs based on the routing configuration of your app, so if you're using them, be sure to specify an appropriate value for `alwaysDefaultFile`, as shown below. (NOTE: Specify the same value if/when configuring the fallback middleware).
206
+
> [!Important]
207
+
In ASP.NET Core, UrlHelper (and the asp-* tag helpers) generate link URIs based on the routing configuration of your app, so if you're using them, be sure to specify an appropriate value for `alwaysDefaultFile`, as shown below. (NOTE: Specify the same value if/when configuring the fallback middleware).
200
208
```c#
201
209
// Sample routes: /, /index, and /page
202
210
//-------------------------------------
@@ -245,7 +253,8 @@ app.GenerateStaticContent(
245
253
246
254
## Scenarios
247
255
248
-
> :bulb: In all scenarios, ensure that routes for static content are unincumbered by authentication or authorization requirements.
256
+
> [!Important]
257
+
> In all scenarios, please ensure that routes for static content are unincumbered by authentication or authorization requirements or anything else that requires user interaction.
249
258
250
259
### Static Site Generation (Standalone SSG)
251
260
@@ -309,7 +318,8 @@ Now you can use the SSG profile to launch your app in SSG mode (to generate stat
309
318
310
319
In this scenario, you want some of the pages in your ASP.NET Core app to be static, but still want other routes to be served as dynamic content per request (e.g. pages/views, JSON API's, etc.). When the app runs, static (.html) files will be generated for routes you specify. The website will then serve these static files for the specified routes, and dynamic content (as usual) for others.
311
320
312
-
> :bulb: While static files are being generated, requests to routes for which a static file has not yet been generated will be served as dynamicly generated content (using the source .cshtml page). Once the static file for that route has been generated, it will be used to satisfy subsequent requests.
321
+
> [!Note]
322
+
> While static files are being generated, requests to routes for which a static file has not yet been generated will be served as dynamicly generated content (using the source .cshtml page). Once the static file for that route has been generated, it will be used to satisfy subsequent requests.
313
323
314
324
The configuration options are generally the same as for a standalone static site, except the following differences:
315
325
- The destination root folder must be `app.Environment.WebRoot` (i.e. wwwroot).
@@ -339,7 +349,8 @@ app.GenerateStaticContent(
339
349
app.Run();
340
350
```
341
351
342
-
> :bulb: The fallback middleware only re-routes requests for routes that match entries in the `PageResources` collection, and only if a generated static file exists for that route.
352
+
> [!Note]
353
+
> The fallback middleware only re-routes requests for routes that match entries in the `PageResources` collection, and does so only if a generated static file exists for that route.
343
354
344
355
345
356
#### Periodic Regeneration
@@ -381,7 +392,8 @@ An `IOptimizerSelector` implementation can select an optimizer based on the attr
381
392
382
393
`DefaultOptimizerSelector` uses the resource type and `OptimizationType` information to select an optimizer.
383
394
384
-
> :bulb: If a given resource requests no optimization (`OptimizationType.None`), or an optimizer implementation is not available for that resource type, `DefaultOptimizerSelector` will return one of the built-in "null" optimizers (`NullMarkupOptimizer`, `NullCssOptimizer`, `NullJsOptimizer`, and `NullBinOptimizer`).
395
+
> [!Note]
396
+
> If a given resource requests no optimization (`OptimizationType.None`), or an optimizer implementation is not available for that resource type, `DefaultOptimizerSelector` will return one of the built-in "null" optimizers (`NullMarkupOptimizer`, `NullCssOptimizer`, `NullJsOptimizer`, and `NullBinOptimizer`).
385
397
386
398
To use your own custom selector, implement the `IOptimizerSelector` interface and register it in the DI container.
> :bulb: If your custom `IOptimizerSelector` implementation injects one or more of the default optimizers provided by AspNetStatic, you must register them by calling `AddDefaultOptimizers()`.
415
+
> [!Important]
416
+
> If your custom `IOptimizerSelector` implementation injects one or more of the default optimizers provided by AspNetStatic, you must register them by calling `AddDefaultOptimizers()`.
The default optimizers provided by AspNetStatic (`DefaultMarkupOptimizer`, `DefaultCssOptimizer`, and `DefaultJsOptimizer`) use the `WebMarkupMin` package to minify HTML, CSS and JS content.
481
494
To override the default minification settings used by AspNetStatic, register the appropriate objects as described below.
482
495
483
-
> :flashlight: For details about WebMarkupMin configuration settings, please consult the [WebMarkupMin documentation](https://github.com/Taritsyn/WebMarkupMin/wiki/).
496
+
<!-- :flashlight: -->
497
+
> [!Tip]
498
+
> For details about WebMarkupMin configuration settings, please consult the [WebMarkupMin documentation](https://github.com/Taritsyn/WebMarkupMin/wiki/).
484
499
485
500
AspNetStatic uses the default `WebMarkupMin` configuration settings (_determined internally by WebMarkupMin_) for minifying HTML, XHTML, and XML content. To override this behavior, register one or more of the following configuration objects:
0 commit comments