|
@@ -507,11 +507,140 @@ const status = await apiClient.getJobStatus(jobId);
|
|
|
The server dynamically generates `/ui/config.js` with runtime configuration:
|
|
The server dynamically generates `/ui/config.js` with runtime configuration:
|
|
|
|
|
|
|
|
```javascript
|
|
```javascript
|
|
|
-window.SD_REST_CONFIG = {
|
|
|
|
|
- apiBaseUrl: 'http://localhost:8080',
|
|
|
|
|
- version: '1.0.0',
|
|
|
|
|
- features: { /* enabled features */ }
|
|
|
|
|
|
|
+window.__SERVER_CONFIG__ = {
|
|
|
|
|
+ apiUrl: 'http://localhost:8080',
|
|
|
|
|
+ apiBasePath: '/api',
|
|
|
|
|
+ host: 'localhost',
|
|
|
|
|
+ port: 8080,
|
|
|
|
|
+ uiVersion: 'a1b2c3d4' // Git commit hash
|
|
|
};
|
|
};
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
This allows the WebUI to adapt to different server configurations without rebuilding.
|
|
This allows the WebUI to adapt to different server configurations without rebuilding.
|
|
|
|
|
+
|
|
|
|
|
+### UI Caching and Versioning
|
|
|
|
|
+
|
|
|
|
|
+The WebUI implements a comprehensive caching strategy with git-based versioning to improve performance and ensure users always see the latest version.
|
|
|
|
|
+
|
|
|
|
|
+#### Git-Based Versioning
|
|
|
|
|
+
|
|
|
|
|
+**Build Process**:
|
|
|
|
|
+1. During `cmake --build build --target webui-build`, the git commit hash is extracted
|
|
|
|
|
+2. A `version.json` file is generated in `/webui/public/` with:
|
|
|
|
|
+ ```json
|
|
|
|
|
+ {
|
|
|
|
|
+ "version": "a1b2c3d4", // Short git hash (8 chars)
|
|
|
|
|
+ "buildTime": "2025-11-02T18:00:00Z"
|
|
|
|
|
+ }
|
|
|
|
|
+ ```
|
|
|
|
|
+3. This file is copied to the build output and served at `/ui/version.json`
|
|
|
|
|
+
|
|
|
|
|
+**Server Implementation** (`src/server.cpp:294-380`):
|
|
|
|
|
+- Reads `version.json` on startup to get current UI version
|
|
|
|
|
+- Injects version into `config.js` as `uiVersion`
|
|
|
|
|
+- Sets HTTP cache headers based on file type and version
|
|
|
|
|
+
|
|
|
|
|
+#### Cache Headers Strategy
|
|
|
|
|
+
|
|
|
|
|
+**Static Assets** (JS, CSS, images, fonts):
|
|
|
|
|
+```http
|
|
|
|
|
+Cache-Control: public, max-age=31536000, immutable
|
|
|
|
|
+ETag: "a1b2c3d4"
|
|
|
|
|
+```
|
|
|
|
|
+- Cached for 1 year (31536000 seconds)
|
|
|
|
|
+- `immutable` flag tells browser file will never change
|
|
|
|
|
+- ETag based on git hash for validation
|
|
|
|
|
+- When version changes, ETag changes, forcing fresh download
|
|
|
|
|
+
|
|
|
|
|
+**HTML Files**:
|
|
|
|
|
+```http
|
|
|
|
|
+Cache-Control: public, max-age=0, must-revalidate
|
|
|
|
|
+ETag: "a1b2c3d4"
|
|
|
|
|
+```
|
|
|
|
|
+- Always revalidate with server (max-age=0)
|
|
|
|
|
+- Can use cached version if ETag matches
|
|
|
|
|
+- Ensures users get latest HTML that references new assets
|
|
|
|
|
+
|
|
|
|
|
+**config.js** (Dynamic Configuration):
|
|
|
|
|
+```http
|
|
|
|
|
+Cache-Control: no-cache, no-store, must-revalidate
|
|
|
|
|
+Pragma: no-cache
|
|
|
|
|
+Expires: 0
|
|
|
|
|
+```
|
|
|
|
|
+- Never cached - always fetched fresh
|
|
|
|
|
+- Contains runtime configuration and current version
|
|
|
|
|
+
|
|
|
|
|
+#### Version Mismatch Detection
|
|
|
|
|
+
|
|
|
|
|
+**Component**: `/webui/components/version-checker.tsx`
|
|
|
|
|
+
|
|
|
|
|
+The `VersionChecker` component:
|
|
|
|
|
+1. Loads current version from `/ui/version.json` on mount
|
|
|
|
|
+2. Reads server version from `window.__SERVER_CONFIG__.uiVersion`
|
|
|
|
|
+3. Compares versions every 5 minutes
|
|
|
|
|
+4. Shows notification banner if versions don't match
|
|
|
|
|
+5. Provides "Refresh" button to reload and get new version
|
|
|
|
|
+
|
|
|
|
|
+**User Experience**:
|
|
|
|
|
+- Users see a yellow notification banner at top of page
|
|
|
|
|
+- Clear message: "New UI Version Available"
|
|
|
|
|
+- One-click refresh to get latest version
|
|
|
|
|
+- Automatic check every 5 minutes (configurable)
|
|
|
|
|
+
|
|
|
|
|
+#### Benefits
|
|
|
|
|
+
|
|
|
|
|
+- ✅ **Performance**: Static assets cached for 1 year, reducing bandwidth and load times
|
|
|
|
|
+- ✅ **Automatic Updates**: Version mismatch detection ensures users know when to refresh
|
|
|
|
|
+- ✅ **Cache Invalidation**: Git hash in ETag guarantees cache busting on updates
|
|
|
|
|
+- ✅ **Reduced Server Load**: Browsers serve most assets from cache
|
|
|
|
|
+- ✅ **Traceability**: Git hash allows tracking exactly which UI version is deployed
|
|
|
|
|
+
|
|
|
|
|
+#### Testing Cache Behavior
|
|
|
|
|
+
|
|
|
|
|
+1. **First Load** (Cache Miss):
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ # Open browser DevTools → Network tab
|
|
|
|
|
+ # Load page → See all assets with Status 200
|
|
|
|
|
+ # Check Response Headers for Cache-Control and ETag
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+2. **Reload** (Cache Hit):
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ # Reload page → See assets with Status 200 (from disk cache)
|
|
|
|
|
+ # Or Status 304 (Not Modified) if revalidating
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+3. **After Rebuild** (Cache Invalidation):
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ # Rebuild UI: cmake --build build --target webui-build
|
|
|
|
|
+ # Restart server
|
|
|
|
|
+ # Reload page → Version checker shows update notification
|
|
|
|
|
+ # Click Refresh → All assets redownloaded with new ETag
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+#### Development vs Production
|
|
|
|
|
+
|
|
|
|
|
+**Development** (`npm run dev`):
|
|
|
|
|
+- Next.js dev server at `localhost:3000`
|
|
|
|
|
+- Hot module replacement (no caching)
|
|
|
|
|
+- Version checking disabled
|
|
|
|
|
+
|
|
|
|
|
+**Production** (served by REST server):
|
|
|
|
|
+- Static files at `/ui/`
|
|
|
|
|
+- Full caching with git versioning
|
|
|
|
|
+- Version checking active
|
|
|
|
|
+- Served from `build/webui/`
|
|
|
|
|
+
|
|
|
|
|
+#### Troubleshooting
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: UI not showing latest changes after rebuild
|
|
|
|
|
+- **Cause**: Browser cache still using old assets
|
|
|
|
|
+- **Solution**: Check version.json was generated correctly, restart server, hard refresh (Ctrl+Shift+R)
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: Version checker not showing update notification
|
|
|
|
|
+- **Cause**: config.js not loaded or version same as cached
|
|
|
|
|
+- **Solution**: Check browser console for errors, verify `window.__SERVER_CONFIG__` exists
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: Assets returning 304 even after version change
|
|
|
|
|
+- **Cause**: Server not reading new version.json
|
|
|
|
|
+- **Solution**: Restart server to reload version file
|