@@ -11,17 +11,15 @@ <h1>My Dashboard</h1>
1111 < div id ="target-placeholder "> Loading plot...</ div >
1212
1313 < script >
14- async function loadPlot ( ) {
14+ async function loadPlot ( url ) {
1515 try {
16- const response = await fetch ( 'bernoulli_eigenvalues.html' ) ;
16+ const response = await fetch ( url ) ;
1717 const htmlString = await response . text ( ) ;
1818
1919 const parser = new DOMParser ( ) ;
2020 const doc = parser . parseFromString ( htmlString , 'text/html' ) ;
2121
22- // IMPROVED: Look for the specific ID, but fallback to the first DIV
23- // if you didn't wrap the source file in a specific container.
24- const plotDiv = doc . getElementById ( 'plotly-graph-container' ) || doc . querySelector ( 'div' ) ;
22+ const plotDiv = doc . querySelector ( 'div' ) ;
2523
2624 if ( ! plotDiv ) {
2725 throw new Error ( "Could not find a div in the source file." ) ;
@@ -44,7 +42,40 @@ <h1>My Dashboard</h1>
4442 }
4543 }
4644
47- loadPlot ( ) ;
45+ async function loadCompressedPlot ( url ) {
46+ try {
47+ // 1. Fetch the .gz file
48+ const response = await fetch ( url ) ;
49+
50+ // 2. Decompress the stream using Gzip format
51+ const ds = new DecompressionStream ( "gzip" ) ;
52+ const decompressedStream = response . body . pipeThrough ( ds ) ;
53+
54+ // 3. Convert stream to text
55+ const reader = await new Response ( decompressedStream ) . text ( ) ;
56+
57+ // 4. Parse and Inject (same logic as before)
58+ const parser = new DOMParser ( ) ;
59+ const doc = parser . parseFromString ( reader , 'text/html' ) ;
60+ const plotDiv = doc . querySelector ( 'div' ) ;
61+
62+ const target = document . getElementById ( 'target-placeholder' ) ;
63+ target . innerHTML = plotDiv . innerHTML ;
64+
65+ // Re-execute scripts
66+ const scripts = target . querySelectorAll ( "script" ) ;
67+ scripts . forEach ( oldScript => {
68+ const newScript = document . createElement ( "script" ) ;
69+ newScript . text = oldScript . text ;
70+ oldScript . parentNode . replaceChild ( newScript , oldScript ) ;
71+ } ) ;
72+
73+ } catch ( err ) {
74+ console . error ( 'Decompression failed:' , err ) ;
75+ }
76+ }
77+
78+ loadCompressedPlot ( 'bernoulli_eigenvalues.html.gz' ) ;
4879 </ script >
4980</ body >
5081</ html >
0 commit comments