stx-router 0.2.764 → 0.2.769

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.
Files changed (2) hide show
  1. package/dist/client.js +27 -0
  2. package/package.json +1 -1
package/dist/client.js CHANGED
@@ -3265,8 +3265,35 @@ else {
3265
3265
  // "hover" (hover and touch still prefetch everything).
3266
3266
  var sightObserver=null;
3267
3267
  var sightCount=0;
3268
+ // Prefetching is for the next page. It must not compete with the paint of
3269
+ // this one, so the first sight-prefetch waits for first contentful paint
3270
+ // (stacksjs/stacks#3082's measurement: two 600 KB documents were already in flight
3271
+ // when the page the person asked for had drawn nothing, three seconds each on a
3272
+ // slow link). A browser without paint timing keeps the immediate behaviour, and
3273
+ // a tab that never paints still gets its prefetches after five seconds.
3274
+ function afterFirstPaint(run){
3275
+ var fired=false;
3276
+ function fire(){ if(fired)return; fired=true; run() }
3277
+ try{
3278
+ var types=typeof PerformanceObserver==='function'&&PerformanceObserver.supportedEntryTypes;
3279
+ if(types&&types.indexOf('paint')>=0){
3280
+ if(performance.getEntriesByName('first-contentful-paint').length){ fire(); return }
3281
+ var po=new PerformanceObserver(function(list){
3282
+ if(!list.getEntriesByName('first-contentful-paint').length)return;
3283
+ po.disconnect(); fire();
3284
+ });
3285
+ po.observe({type:'paint',buffered:true});
3286
+ setTimeout(fire,5000);
3287
+ return;
3288
+ }
3289
+ }catch(e){}
3290
+ fire();
3291
+ }
3268
3292
  function observeLinks(){
3269
3293
  if(!o.prefetch||!o.cache||o.prefetchVisible===false||typeof IntersectionObserver!=='function')return;
3294
+ afterFirstPaint(observeLinksNow);
3295
+ }
3296
+ function observeLinksNow(){
3270
3297
  var c=navigator.connection;
3271
3298
  if(c&&(c.saveData||/2g/.test(c.effectiveType||'')))return;
3272
3299
  if(!sightObserver)sightObserver=new IntersectionObserver(function(entries){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stx-router",
3
3
  "type": "module",
4
- "version": "0.2.764",
4
+ "version": "0.2.769",
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",