feat: Add Universal Editor cache-busting utilities#45
Open
skukla wants to merge 6 commits intodemo-system-stores:mainfrom
Open
feat: Add Universal Editor cache-busting utilities#45skukla wants to merge 6 commits intodemo-system-stores:mainfrom
skukla wants to merge 6 commits intodemo-system-stores:mainfrom
Conversation
Extracted UE detection and cache-busting logic into reusable
utilities in scripts/utils.js:
- isUniversalEditor() - Detects UE or localhost context
- fetchWithCacheBusting() - Fetch wrapper with cache: reload in UE
Benefits:
- Centralized UE detection logic (single source of truth)
- Easy for any block to use via import from aem.js
- Explicit opt-in (blocks choose to use utility)
- Maintainable (one place to update)
- Well-documented with JSDoc
Updated fragment.js to use the new utility, removing
inline detection code.
Exported from aem.js for easy access:
import { fetchWithCacheBusting } from '../../scripts/aem.js';
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Comprehensive guide explaining: - Problem: Fragment caching in UE preventing authors from seeing updates - Solution: Utility functions for UE detection and cache-busting - Automatic coverage via loadFragment() - Developer usage examples for custom blocks - Technical details and benefits 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Creates a minimal test block to demonstrate fetchWithCacheBusting() utility usage for non-fragment blocks. - blocks/test-cache-busting/test-cache-busting.js - Fetches JSON data - test-data.json - Sample data file for testing Test procedure: 1. Create document with test-cache-busting block in da.live 2. Edit test-data.json in da.live 3. Publish changes 4. Reload page in UE - verify updated content appears immediately This demonstrates that the cache-busting utility works for ANY block that fetches content, not just fragments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Resolves ESLint comma-dangle error on line 152. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The test data will be created as a sheet in da.live for easier editing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
/scripts/utils.js- Global utilities (isUniversalEditor(),fetchWithCacheBusting())/blocks/fragment/fragment.js- Uses cache-busting for all fragments/scripts/aem.js- Exports utilities for block developers/docs/cache-busting.md- Developer documentation/blocks/product-list-page/product-list-page.js- Trailing comma linting issueProblem Solved
When authors edit fragments in Universal Editor and publish changes, they don't see updates immediately due to browser caching. This creates confusion during the authoring experience.
Solution
The utilities automatically detect UE context (
.ue.da.liveorlocalhost) and usecache: 'reload'to bypass HTTP cache. Production sites continue using normal browser caching for performance.Test Plan