Skip to content

perf(api): optimize static asset caching, enable ETag support, and expand response compression mime types.#6273

Open
balazs-szucs wants to merge 5 commits intoStirling-Tools:mainfrom
balazs-szucs:backend-resource-caching
Open

perf(api): optimize static asset caching, enable ETag support, and expand response compression mime types.#6273
balazs-szucs wants to merge 5 commits intoStirling-Tools:mainfrom
balazs-szucs:backend-resource-caching

Conversation

@balazs-szucs
Copy link
Copy Markdown
Collaborator

Description of Changes

This PR implements a caching strategy for Stirling-PDF assets and API endpoints. It aligns the backend with modern SPA best practices, ensuring maximum performance for repeat visitors while guaranteeing immediate invalidation upon new deployments.

  1. Granular Cache Tiering (WebMvcConfig.java)
  • Vite-Hashed Assets (/assets/**): Configured as public, max-age=31536000, immutable. Since filenames are fingerprinted by Vite, these never need to be revalidated.
  • Shell-Critical Metadata (/sw.js, /manifest.json): Configured as no-store to ensure the PWA lifecycle and atomic updates are handled safely by the browser.
  • Branding Assets (Logos, Icons): Implemented Stale-While-Revalidate (max-age=1d, stale-while-revalidate=7d). This allows for immediate visual feedback while the browser revalidates branding changes in the background.
  • Static Media & Fonts: Set to 1-year immutable caching to reduce redundant network requests for stable libraries like PDF.js.
  1. API & SPA Freshness
  • Global API Default: Updated EndpointInterceptor to set Cache-Control: no-cache for all /api/** routes. This forces browsers to revalidate dynamic data with the server (leveraging Last-Modified or ETags).
  • SPA Entry Point: Updated ReactRoutingController to serve index.html with no-cache, ensuring users always receive the latest application bundle after a deployment.
  1. Optimization & Cleanup
  • Expanded Compression: Added image/svg+xml and modern font formats (woff2, ttf, otf, eot) to the server's compression MIME types.
  • Reduced Overhead: Removed redundant VersionResourceResolver and ShallowEtagHeaderFilter. We now rely on Vite's native fingerprinting and Spring's built-in Last-Modified support, which avoids memory-intensive response buffering.

Checklist

General

Documentation

Translations (if applicable)

UI Changes (if applicable)

  • Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)

Testing (if applicable)

  • I have run task check to verify linters, typechecks, and tests pass
  • I have tested my changes locally. Refer to the Testing Guide for more details.

@stirlingbot stirlingbot Bot added Java Pull requests that update Java code Back End Issues related to back-end development API API-related issues or pull requests perf Changes that improve performance labels Apr 30, 2026
@balazs-szucs balazs-szucs marked this pull request as ready for review April 30, 2026 09:53
Copilot AI review requested due to automatic review settings April 30, 2026 09:53
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines ignoring generated files. label Apr 30, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Spring MVC/static resource handling and response headers to implement a more explicit caching strategy for SPA assets and API responses, along with expanding server-side compression MIME types to improve repeat-visit performance.

Changes:

  • Expanded server.compression.mime-types to include SVG and additional font MIME types.
  • Updated ReactRoutingController to add Cache-Control: no-cache behavior when serving index.html.
  • Reworked WebMvcConfig static resource handlers to apply tiered cache policies (immutable for hashed assets, no-store for PWA metadata, etc.) and added a global API cache header in EndpointInterceptor.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
app/core/src/main/resources/application.properties Expands compression MIME types for additional asset formats.
app/core/src/main/java/stirling/software/SPDF/controller/web/ReactRoutingController.java Adds Cache-Control directives for SPA entry point responses.
app/core/src/main/java/stirling/software/SPDF/config/WebMvcConfig.java Introduces tiered cache policies for different static asset groups.
app/core/src/main/java/stirling/software/SPDF/config/EndpointInterceptor.java Sets a default Cache-Control header for /api/** responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/core/src/main/resources/application.properties Outdated
Comment thread app/core/src/main/java/stirling/software/SPDF/config/WebMvcConfig.java Outdated
Comment thread app/core/src/main/java/stirling/software/SPDF/config/WebMvcConfig.java Outdated
Comment thread app/core/src/main/java/stirling/software/SPDF/config/EndpointInterceptor.java Outdated
Comment thread app/core/src/main/java/stirling/software/SPDF/config/EndpointInterceptor.java Outdated
ConnorYoh
ConnorYoh previously approved these changes Apr 30, 2026
reecebrowne
reecebrowne previously approved these changes Apr 30, 2026
# Conflicts:
#	app/core/src/main/java/stirling/software/SPDF/config/EndpointInterceptor.java
@balazs-szucs balazs-szucs dismissed stale reviews from reecebrowne and ConnorYoh via f50e4eb May 2, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API-related issues or pull requests Back End Issues related to back-end development Java Pull requests that update Java code perf Changes that improve performance size:L This PR changes 100-499 lines ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants