Remote Theme Optimization
How to prevent whitescreen and FOUC when using Arsxy Theme as a remote theme
Remote Theme Optimization
When using Arsxy Theme as a remote theme (via remote_theme in _config.yml), you might experience a brief whitescreen or Flash of Unstyled Content (FOUC) during page loads. This document explains why this happens and what we’ve done to fix it.
The Problem
When using a remote theme, Jekyll needs to:
- Download theme files from GitHub
- Process and compile SCSS files
- Load CSS in the browser
- Apply dark mode preferences
This process can create a timing gap where the page shows a white background before the proper theme styles load.
Our Solution
We’ve implemented several optimizations to prevent this issue:
1. Critical CSS File
We load a separate critical CSS file (critical.css) before the main CSS that:
- Sets immediate background colors for both light and dark modes
- Applies proper theme colors before external CSS loads
- Uses the exact same SCSS variables as the main theme files
- Maintains all styles in maintainable SCSS format
2. Optimized Loading Strategy
- Main CSS loads synchronously to prevent FOUC
- Non-critical styles load asynchronously for performance
- Color scheme hints help browsers prepare for theme switching
3. Enhanced Dark Mode Detection
The dark mode detection script:
- Runs immediately in an IIFE (Immediately Invoked Function Expression)
- Includes error handling for localStorage access
- Adds loading states for smoother transitions
- Works correctly even if external resources are slow to load
4. Browser Optimization Hints
Added meta tags to help browsers:
<meta name="color-scheme" content="light dark">
This tells browsers to use appropriate default colors while loading.
Usage as Remote Theme
To use Arsxy Theme as a remote theme, add this to your _config.yml:
remote_theme: awcodify/arsxy-theme
The optimization is automatic - no additional configuration needed.
Performance Impact
These optimizations have minimal impact:
- Critical CSS adds ~1KB inline (gzipped)
- Dark mode script runs in ~5ms
- Overall page load feels smoother and more responsive
Troubleshooting
If you still experience issues:
- Verify your config: Ensure
remote_theme: awcodify/arsxy-themeis in_config.yml - Check browser cache: Clear cache and hard refresh (
Ctrl+F5orCmd+Shift+R) - Test in incognito: Try in a private/incognito window
- GitHub Pages delay: Remote theme changes may take 5-10 minutes to propagate
Technical Details
Critical CSS Colors
The inline critical CSS uses these exact colors from the theme:
Light Mode:
- Background:
#ffffff(from$background-color) - Text:
#2c3e50(from$text-color)
Dark Mode:
- Background:
#0f172a(from$dark-background) - Text:
#e2e8f0(from$dark-text-color) - Surface:
#1e293b(from$dark-surface)
Loading States
The theme uses CSS classes to manage loading:
.theme-loading: Applied during initial theme detection.theme-ready: Applied when theme is fully configured
This allows for smooth transitions and prevents jarring switches.