30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
| {{ if eq hugo.Environment "development" }}
 | |
| <script>
 | |
|   // Initialize LiveReload WebSocket after page load
 | |
|   // This ensures our WebSocket solution works properly with the bfcache
 | |
|   document.addEventListener('DOMContentLoaded', function() {
 | |
|     // Small delay to ensure Hugo's scripts have run
 | |
|     setTimeout(function() {
 | |
|       // Only if no WebSocket is active yet
 | |
|       if (!window.__bfcacheLiveReloadActive) {
 | |
|         const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
 | |
|         const wsUrl = `${protocol}//${window.location.host}/__livereload`;
 | |
|         try {
 | |
|           // Create the WebSocket using the original constructor
 | |
|           if (window.OriginalWebSocket) {
 | |
|             const socket = new window.OriginalWebSocket(wsUrl);
 | |
|             socket.onmessage = function(e) {
 | |
|               if (e.data === 'reload') {
 | |
|                 window.location.reload();
 | |
|               }
 | |
|             };
 | |
|             window.__bfcacheLiveReloadActive = true;
 | |
|           }
 | |
|         } catch (e) {
 | |
|           console.warn('LiveReload connection error:', e);
 | |
|         }
 | |
|       }
 | |
|     }, 500);
 | |
|   });
 | |
| </script>
 | |
| {{ end }}  |