Skip to content

dotnet watch run should refresh the browser window when static files are changed #27047

@DamianEdwards

Description

@DamianEdwards

Add support for dotnet watch run to refresh the browser window when changes to static files are detected.

  • Default set of static files watched should include: *.css, *.js, *.jpg, *.png, *.gif
  • Static files to watch should be configurable via existing mechanism in MSBuild (i.e. <Watch /> item type and watch item metadata)
  • When changes to configured static files are detected the browser should have the content cache for the current app cleared via the Clear-Site-Data header before being refreshed
    • Note this capability needs to be investigated to determine its utility and applicability to this feature, along with the best way to incorporate it, e.g. as a separate Fetch request to the app site before the refresh, or as an added response header to the next HTML response from the site after a change is detected.
  • The different actions performed by dotnet watch run when changes to different files are detected should be represented via MSBuild metadata like the file watch list itself, e.g. build and refresh browser, build only, refresh browser only, dynamically swap out image/CSS (future), etc. This will allow for customization by the user for more advanced scenarios along with different defaults for different app models (e.g. Blazor component CSS must be rebuilt due to the CSS isolation feature)
    • Approach 1, different metadata attribute per action:
      <Content Include="**/*.css" Watch="true" OnWatchChangeBuild="False" OnWatchChangeRefreshBrowser="True"  />
    • Approach 2, single metadata attribute but multiple values:
      <Content Include="**/*.css" Watch="true" OnWatchChange="RefreshBrowser;SomethingElse"  />

Metadata

Metadata

Assignees

Labels

Theme: inner-loopaffected-fewThis issue impacts only small number of customersarea-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPIenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-hot-reloadThis issue is related to the Hot Reload feaatureseverity-nice-to-haveThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions