llamameta commited on
Commit
301335b
·
verified ·
1 Parent(s): f392227

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +39 -10
index.html CHANGED
@@ -4,6 +4,12 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Black Forest Labs - Load Balanced Streamlit</title>
 
 
 
 
 
 
7
  <style>
8
  html, body {
9
  margin: 0;
@@ -36,16 +42,23 @@
36
  <iframe id="streamlit-frame"></iframe>
37
 
38
  <script>
 
 
 
 
39
  const SERVERS = [
40
- "https://geminisearchv2-nuugs4gfc8vaybhs9yzmuh.streamlit.app/?embed=true",
41
- "https://geminisearchv2-nuugs4gfc8vaybhs9yzmuh.streamlit.app/?embed=true"
42
  ];
43
 
44
- // Fungsi untuk mengecek kecepatan respons server
45
  async function checkServerSpeed(url) {
46
  const start = performance.now();
47
  try {
48
- const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
 
 
 
49
  const end = performance.now();
50
  return end - start;
51
  } catch (error) {
@@ -66,20 +79,36 @@
66
  const loadingElement = document.getElementById('loading');
67
  const iframe = document.getElementById('streamlit-frame');
68
 
69
- // Cek apakah sudah ada URL yang tersimpan di sessionStorage
70
- let chosenUrl = sessionStorage.getItem('streamlitUrl');
 
71
 
72
  if (!chosenUrl) {
73
- // Jika belum ada, pilih server dan simpan ke sessionStorage
74
  chosenUrl = await chooseServer();
75
- sessionStorage.setItem('streamlitUrl', chosenUrl);
76
  }
77
 
78
- // Tampilkan iframe dan sembunyikan loading
79
- iframe.src = chosenUrl;
 
 
 
 
 
 
80
  iframe.onload = () => {
81
  loadingElement.style.display = 'none';
82
  };
 
 
 
 
 
 
 
 
 
83
  }
84
 
85
  // Jalankan loadStreamlit saat halaman dimuat
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Black Forest Labs - Load Balanced Streamlit</title>
7
+
8
+ <!-- Meta tags untuk mencegah caching halaman HTML -->
9
+ <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
10
+ <meta http-equiv="Pragma" content="no-cache">
11
+ <meta http-equiv="Expires" content="0">
12
+
13
  <style>
14
  html, body {
15
  margin: 0;
 
42
  <iframe id="streamlit-frame"></iframe>
43
 
44
  <script>
45
+ // Ganti ini dengan versi baru setiap kali Anda update link SERVERS (misalnya "v2", "v3", dll.)
46
+ const VERSION = "v4"; // Ubah ini ke nilai baru untuk memaksa update (contoh: "v2" saat link berubah)
47
+
48
+ // Array server dengan link baru Anda (ganti sesuai kebutuhan)
49
  const SERVERS = [
50
+ "https://geminisearchv4-98spcxxh9ybnwlmgborvn4.streamlit.app/?embed=true", // Ganti dengan link baru
51
+ "https://geminisearchv4-98spcxxh9ybnwlmgborvn4.streamlit.app/?embed=true" // Ganti dengan link baru
52
  ];
53
 
54
+ // Fungsi untuk mengecek kecepatan respons server (sama seperti sebelumnya, tapi tambah timeout)
55
  async function checkServerSpeed(url) {
56
  const start = performance.now();
57
  try {
58
+ const response = await Promise.race([
59
+ fetch(url, { method: 'HEAD', mode: 'no-cors' }),
60
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), 5000)) // Timeout 5 detik
61
+ ]);
62
  const end = performance.now();
63
  return end - start;
64
  } catch (error) {
 
79
  const loadingElement = document.getElementById('loading');
80
  const iframe = document.getElementById('streamlit-frame');
81
 
82
+ // Gunakan key sessionStorage dengan VERSION untuk cache busting
83
+ const storageKey = `streamlitUrl_${VERSION}`;
84
+ let chosenUrl = sessionStorage.getItem(storageKey);
85
 
86
  if (!chosenUrl) {
87
+ // Jika belum ada atau version berubah, pilih server baru dan simpan
88
  chosenUrl = await chooseServer();
89
+ sessionStorage.setItem(storageKey, chosenUrl);
90
  }
91
 
92
+ // Tambahkan cache busting ke URL iframe (timestamp unik)
93
+ const cacheBuster = new Date().getTime(); // Timestamp untuk memaksa no-cache
94
+ const iframeSrc = `${chosenUrl}&cb=${cacheBuster}`; // Append ?cb=timestamp jika URL sudah punya query
95
+
96
+ // Set src iframe
97
+ iframe.src = iframeSrc;
98
+
99
+ // Event onload untuk sembunyikan loading
100
  iframe.onload = () => {
101
  loadingElement.style.display = 'none';
102
  };
103
+
104
+ // Fallback: Jika iframe gagal load (misalnya URL lama invalid), pilih ulang
105
+ iframe.onerror = async () => {
106
+ console.warn('Iframe load failed, rechoosing server...');
107
+ sessionStorage.removeItem(storageKey); // Hapus storage lama
108
+ chosenUrl = await chooseServer();
109
+ sessionStorage.setItem(storageKey, chosenUrl);
110
+ iframe.src = `${chosenUrl}&cb=${new Date().getTime()}`;
111
+ };
112
  }
113
 
114
  // Jalankan loadStreamlit saat halaman dimuat