stx-router 0.2.783 → 0.2.785
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/client.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,6 +165,9 @@ Background page prefetches and revalidations run at most two at a time. Hover or
|
|
|
165
165
|
touch intent moves a queued page ahead of links merely visible on screen. A
|
|
166
166
|
navigation starts its queued destination immediately and shares that request,
|
|
167
167
|
so it never waits for the speculative queue or fetches the page twice.
|
|
168
|
+
Speculative HTML requests declare `Purpose: prefetch`, including cross-layout
|
|
169
|
+
document fallback, background revalidation and `router.prefetch()`. Ordinary
|
|
170
|
+
navigation requests do not carry that declaration.
|
|
168
171
|
|
|
169
172
|
### Route Type Generation
|
|
170
173
|
|
package/dist/client.js
CHANGED
|
@@ -3218,12 +3218,17 @@ else {
|
|
|
3218
3218
|
// for once more behind the swap. If it changed, the cache takes the new copy
|
|
3219
3219
|
// and stx:updated says so, so the page can refresh what it shows; the
|
|
3220
3220
|
// screen is never swapped out from under the user.
|
|
3221
|
+
function prefetchHeaders(fragment){
|
|
3222
|
+
var headers={'Accept':'text/html','Purpose':'prefetch'};
|
|
3223
|
+
if(fragment)headers['X-STX-Router']='true';
|
|
3224
|
+
return headers;
|
|
3225
|
+
}
|
|
3221
3226
|
function revalidate(key,url){
|
|
3222
3227
|
if(!o.revalidate||!o.cache||!key||prefetching[key])return;
|
|
3223
3228
|
if(Date.now()-(cacheAt[key]||0)<o.revalidateAfter)return;
|
|
3224
3229
|
// Compare like with like, including documents prefetched across layouts.
|
|
3225
3230
|
var before=cache[key],wantsFragment=before?isFragment(before):shouldUseFragmentResponse();
|
|
3226
|
-
prefetching[key]=queuePrefetch(key,function(){return fetch(url,{priority:'low',headers:wantsFragment
|
|
3231
|
+
prefetching[key]=queuePrefetch(key,function(){return fetch(url,{priority:'low',headers:prefetchHeaders(wantsFragment)}).then(function(r){
|
|
3227
3232
|
var incoming=r.headers.get('X-STX-Build')||'';
|
|
3228
3233
|
if(isBuildSkew(incoming)){reloadForSkew(url,incoming,true);return null}
|
|
3229
3234
|
return readPrefetchResponse(r,wantsFragment);
|
|
@@ -3640,7 +3645,7 @@ else {
|
|
|
3640
3645
|
}
|
|
3641
3646
|
var eager=link.getAttribute('data-stx-prefetch')==='eager';
|
|
3642
3647
|
var wantsFragment=shouldUseFragmentResponse();
|
|
3643
|
-
prefetching[key]=queuePrefetch(key,function(){return fetch(href,{priority:'low',headers:wantsFragment
|
|
3648
|
+
prefetching[key]=queuePrefetch(key,function(){return fetch(href,{priority:'low',headers:prefetchHeaders(wantsFragment)}).then(function(r){
|
|
3644
3649
|
return readPrefetchResponse(r,wantsFragment);
|
|
3645
3650
|
}).then(function(result){
|
|
3646
3651
|
// A page in another layout cannot be swapped in as a fragment: the tap
|
|
@@ -3649,7 +3654,7 @@ else {
|
|
|
3649
3654
|
// still reaching for the link, so the tap is a swap like any other.
|
|
3650
3655
|
if(!result||!isFragment(result.html)||!checkLayoutChange(result.layout,href,result.layoutGroup))return result;
|
|
3651
3656
|
// Same guards as any prefetch; the layout is the one the fragment declared.
|
|
3652
|
-
return fetch(href,{priority:'low',headers:
|
|
3657
|
+
return fetch(href,{priority:'low',headers:prefetchHeaders(false)}).then(function(full){
|
|
3653
3658
|
return full.ok?readPrefetchResponse(full,false).then(function(doc){return doc&&(doc.layout=result.layout,doc.layoutGroup=result.layoutGroup,doc)}):null;
|
|
3654
3659
|
});
|
|
3655
3660
|
}).then(function(result){
|
|
@@ -4047,7 +4052,7 @@ else {
|
|
|
4047
4052
|
var key=cacheKey(url);
|
|
4048
4053
|
if(!cache[key]){
|
|
4049
4054
|
var wantsFragment=shouldUseFragmentResponse();
|
|
4050
|
-
fetch(url,{headers:wantsFragment
|
|
4055
|
+
fetch(url,{headers:prefetchHeaders(wantsFragment)}).then(function(r){return readPrefetchResponse(r,wantsFragment)}).then(function(result){if(result)setCache(key,result.html,result.layout,result.layoutGroup,result.title,result.containerAttrs)}).catch(function(){});
|
|
4051
4056
|
}
|
|
4052
4057
|
},
|
|
4053
4058
|
// Re-run the CURRENT route against the server and swap the result.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stx-router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.785",
|
|
5
5
|
"description": "File-based router for STX — .stx template discovery, nested layouts, typed route params, middleware, and client-side SPA navigation.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|