Skip to content

fix html and js cache errors#179

Merged
mitch10593 merged 2 commits intomainfrom
fix/178-fix-404-and-mime-errors-on-stale-vite-assets-after-redeployment
Mar 12, 2026
Merged

fix html and js cache errors#179
mitch10593 merged 2 commits intomainfrom
fix/178-fix-404-and-mime-errors-on-stale-vite-assets-after-redeployment

Conversation

@mitch10593
Copy link
Copy Markdown
Contributor

@mitch10593 mitch10593 commented Mar 12, 2026

Summary by Sourcery

Adjust frontend and deployment Nginx caching rules to prevent stale HTML/JS while keeping static asset caching, and document the change in the changelog.

Bug Fixes:

  • Disable caching for index.html to ensure the SPA entry point is always fetched fresh and avoid stale HTML/JS issues.

Enhancements:

  • Separate Vite hashed assets into a dedicated location block that serves real 404s instead of falling back to the SPA entrypoint.
  • Forward cache-related headers from the frontend Nginx to the deploy Nginx proxy to preserve caching behavior across layers.

Documentation:

  • Update the changelog with a new 2.1.1 entry describing the frontend cache fix.

@mitch10593 mitch10593 added this to the 2.1 milestone Mar 12, 2026
@mitch10593 mitch10593 self-assigned this Mar 12, 2026
@mitch10593 mitch10593 linked an issue Mar 12, 2026 that may be closed by this pull request
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 12, 2026

Reviewer's Guide

Adjusts nginx frontend and deploy configurations to ensure index.html is never cached, Vite-generated assets are served with strict long-term caching and proper 404s, and cache headers from the frontend are propagated through the deploy proxy, with changelog updated for version 2.1.1.

File-Level Changes

Change Details Files
Ensure SPA entry point index.html is never cached by clients or intermediaries.
  • Added a dedicated location block for /index.html with no-cache, no-store, must-revalidate Cache-Control header.
  • Added Pragma and Expires headers to further prevent caching of index.html.
frontend/nginx.conf
Differentiate caching behavior for Vite-hashed assets versus other static assets and enforce real 404s for missing hashed assets.
  • Introduced a specific /assets/ location with 1-year immutable caching and try_files to return 404 when missing.
  • Retained and relabeled the generic static assets location for other file types with long-term immutable caching and SPA fallback unaffected.
frontend/nginx.conf
Propagate cache-related headers from the frontend nginx through the deploy nginx reverse proxy.
  • Configured deploy nginx to pass through Cache-Control, Pragma, and Expires headers from the upstream frontend service.
deploy/nginx.conf
Document the cache fix in the project changelog.
  • Added version 2.1.1 entry describing the HTML and JS frontend cache fix.
CHANGELOG.md

Assessment against linked issues

Issue Objective Addressed Explanation
#178 Update frontend/nginx.conf so that index.html is never cached and Vite assets under /assets/ return 404 (no SPA fallback) while remaining long-lived cached when they exist.
#178 Update deploy/nginx.conf to forward Cache-Control-related headers (Cache-Control, Pragma, Expires) from the frontend nginx to clients.

Possibly linked issues

  • #(no explicit number provided): PR adds no-cache for index.html, proper /assets try_files, and proxy_pass_header directives, matching the issue’s solution.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • Consider adding the always flag to the add_header directives for the HTML no-cache rules so they also apply to 304/4xx/5xx responses (e.g. add_header Cache-Control "no-cache, no-store, must-revalidate" always;), which helps ensure browsers don’t cache error or conditional responses.
  • By carving out /assets/ with long-lived immutable caching, you’re assuming everything under that path is fingerprinted; if that’s not guaranteed for all current and future assets, you may want a narrower pattern (e.g. only hashed filenames) to avoid accidentally locking in stale non-hashed resources for a year.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding the `always` flag to the `add_header` directives for the HTML no-cache rules so they also apply to 304/4xx/5xx responses (e.g. `add_header Cache-Control "no-cache, no-store, must-revalidate" always;`), which helps ensure browsers don’t cache error or conditional responses.
- By carving out `/assets/` with long-lived immutable caching, you’re assuming everything under that path is fingerprinted; if that’s not guaranteed for all current and future assets, you may want a narrower pattern (e.g. only hashed filenames) to avoid accidentally locking in stale non-hashed resources for a year.

## Individual Comments

### Comment 1
<location path="frontend/nginx.conf" line_range="25-30" />
<code_context>
     }

+    # Never cache index.html (SPA entry point — must always fetch latest)
+    location = /index.html {
+        add_header Cache-Control "no-cache, no-store, must-revalidate";
+        add_header Pragma "no-cache";
+        add_header Expires "0";
+    }
+
</code_context>
<issue_to_address>
**suggestion:** Consider using `add_header ... always;` so the no-cache headers apply to 304s and non-200 responses as well.

Without `always`, these headers may not be sent on 304s or some error responses (depending on nginx version/config), so `/index.html` can still be cached in those cases. For an SPA entry point that must never be cached, consider:

```nginx
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
```

This enforces no-cache semantics consistently, including on conditional and error responses.

```suggestion
    # Never cache index.html (SPA entry point — must always fetch latest)
    location = /index.html {
        add_header Cache-Control "no-cache, no-store, must-revalidate" always;
        add_header Pragma "no-cache" always;
        add_header Expires "0" always;
    }
```
</issue_to_address>

### Comment 2
<location path="CHANGELOG.md" line_range="3" />
<code_context>
+## 2.1.1
+
+- FIXED system - html and js frontend cache cause failures
+
 ## 2.1.0
</code_context>
<issue_to_address>
**suggestion (typo):** Consider fixing capitalization and grammar in this changelog entry.

For example, you could write: `- FIXED system - HTML and JS frontend caches causing failures` or `- FIXED system - HTML and JS frontend cache caused failures`.

```suggestion
- FIXED system - HTML and JS frontend caches causing failures
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mitch10593 mitch10593 merged commit 2886191 into main Mar 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: 404 and MIME errors on stale Vite assets after redeployment

1 participant