-
-
Notifications
You must be signed in to change notification settings - Fork 80
Build fix #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build fix #334
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| using System.Collections.Generic; | ||
| using System.Configuration; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Reflection; | ||
|
|
@@ -26,6 +27,7 @@ | |
| using Microsoft.Extensions.Caching.StackExchangeRedis; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.FileProviders; | ||
| using Microsoft.Extensions.Logging; | ||
| using Resgrid.Config; | ||
| using Resgrid.Framework; | ||
|
|
@@ -375,10 +377,6 @@ public void ConfigureServices(IServiceCollection services) | |
| pipeline.AddCssBundle("/css/pub-bundle.css", | ||
| "css/style.css", "css/animate.css", "lib/font-awesome/css/font-awesome.min.css"); | ||
|
|
||
| // Angular App code | ||
| pipeline.AddJavaScriptBundle("/js/ng/app.js", | ||
| "js/ng/vendor.js", "js/ng/runtime.js", "js/ng/polyfills.js", "js/ng/main.js"); | ||
|
|
||
| // Internal app style bundle | ||
| pipeline.AddCssBundle("/css/int-bundle.css", | ||
| "lib/font-awesome/css/font-awesome.min.css", "lib/metisMenu/dist/metisMenu.min.css", "lib/bootstrap-tour/build/css/bootstrap-tour.min.css", | ||
|
|
@@ -586,6 +584,26 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF | |
|
|
||
| app.UseCookiePolicy(cookiePolicyOptions); | ||
|
|
||
| // Serve the Vite ESM assets directly so legacy optimization doesn't rewrite module chunks. | ||
| app.UseWhen( | ||
| context => context.Request.Path.StartsWithSegments("/js/ng"), | ||
| clientApp => | ||
| { | ||
| clientApp.UseStaticFiles(new StaticFileOptions | ||
| { | ||
| FileProvider = new PhysicalFileProvider(Path.Combine(env.WebRootPath, "js", "ng")), | ||
| RequestPath = "/js/ng", | ||
| OnPrepareResponse = context => | ||
| { | ||
| var cacheControl = context.Context.Request.Path.StartsWithSegments("/js/ng/chunks") | ||
| ? "public,max-age=31536000,immutable,no-transform" | ||
| : "no-cache,no-transform"; | ||
|
|
||
| context.Context.Response.Headers["Cache-Control"] = cacheControl; | ||
| } | ||
| }); | ||
| }); | ||
|
Comment on lines
+592
to
+605
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm whether the Vite output directory is expected to always exist at Configure-time
# (e.g. checked in, produced by an msbuild target, or a pre-run step).
fd -t d -u '^ng$' | rg -n 'wwwroot/js/ng'
rg -nP --type=xml -C2 '(js[/\\\\]ng|vite|npm (run )?build)' -g '*.csproj'
rg -nP -C2 '(js[/\\\\]ng|vite\s+build|npm\s+run\s+build)' -g '!node_modules' -g '!*.min.*' -g '!*.map'Repository: Resgrid/Core Length of output: 6521 🏁 Script executed: #!/bin/bash
# Check if wwwroot/js/ng exists in git (not gitignored)
git ls-files | grep -E 'wwwroot/js/ng'
# Check .gitignore patterns that might exclude this directory
cat .gitignore 2>/dev/null | grep -E '(wwwroot|js|ng|/dist)' || echo "No gitignore patterns found matching"
# Check if wwwroot itself is gitignored
git check-ignore -v 'Web/Resgrid.Web/wwwroot' 2>/dev/null || echo "wwwroot is not gitignored"
git check-ignore -v 'Web/Resgrid.Web/wwwroot/js/ng' 2>/dev/null || echo "wwwroot/js/ng is not gitignored"
# List what's actually in the directory in git
echo "=== Files in wwwroot/js/ng in git ==="
git ls-files | grep 'wwwroot/js/ng' | head -20 || echo "No files found in git"Repository: Resgrid/Core Length of output: 2726 Cache-Control headers should apply Per vite.config.ts, both Update the cache-control logic to treat all hashed assets uniformly. 🤖 Prompt for AI Agents |
||
|
|
||
| app.UseWebOptimizer(); | ||
| app.UseStaticFiles(); | ||
| app.UseRouting(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hashed
/js/ng/assets/*files are missing the immutable cache policy.The
vite.config.tsreferenced in context emits three output groups, but only one of them is being treated as immutable here:react-elements.js— entry, not hashed →no-cache✅ correctchunks/[name]-[hash].js— hashed →immutable✅ correctassets/[name]-[hash][extname]— hashed → currentlyno-cache❌/js/ng/assets/*is content-hashed just likechunks/*, so it's equally safe for long-term immutable caching. As written, browsers will revalidate those fingerprinted assets on every navigation, which negates the hashing strategy.♻️ Suggested tweak
OnPrepareResponse = context => { - var cacheControl = context.Context.Request.Path.StartsWithSegments("/js/ng/chunks") + var path = context.Context.Request.Path; + var isHashed = path.StartsWithSegments("/js/ng/chunks") + || path.StartsWithSegments("/js/ng/assets"); + var cacheControl = isHashed ? "public,max-age=31536000,immutable,no-transform" : "no-cache,no-transform"; context.Context.Response.Headers["Cache-Control"] = cacheControl; }📝 Committable suggestion
🤖 Prompt for AI Agents