WSL delays serving local JavaScript, CSS, and font files due to high latency when accessing Windows filesystems from Linux. This occurs because WSL translates NTFS file operations over SMB, causing significant overhead for small, frequent requests. To resolve this, you must move your web project into the native Linux filesystem rather than keeping it in the mounted Windows directory.
The Root Cause of Filesystem Latency
When you run a web server like Apache 2.4.52 inside Ubuntu 22.04 on Windows 11, the location of your source files determines performance. By default, many developers store their projects in /mnt/c/Users/YourName/Projects. This path points to the Windows C: drive, which is accessible via the \\wsl$\ network share protocol.
Every time your browser requests a static asset such as a .js or .css file, WSL must translate that request through the SMB layer to Windows. Small files generate a high volume of I/O operations. The overhead of these translations accumulates, leading to noticeable delays in serving resources. HTML files may load slowly, but assets often fail to appear entirely or load with a significant timeout. This behavior is not a bug in Apache but a fundamental limitation of cross-OS filesystem access.
Step-by-Step Solution
The only reliable fix is to ensure your development files reside entirely within the ext4 virtual disk used by WSL. Follow these steps to migrate your project:
- Locate your current project: Identify where your web root currently lives. If it is under
/mnt/c/,/mnt/d/, or any other mounted Windows drive, it needs to move. - Navigate to the Linux home directory: Open your WSL terminal and go to your home folder using
cd ~. - Create a new project directory: Run
mkdir -p ~/projects/my-web-appto create a dedicated space in the native Linux filesystem. - Copy your files: Use the
cpcommand to transfer your code. For example:cp -r /mnt/c/Users/YourName/Projects/my-web-app/* ~/projects/my-web-app/. Ensure you include hidden files if necessary by using-ainstead of justr. - Update Apache configuration: Edit your Apache virtual host file. Change the
DocumentRootdirective to point to the new Linux path, such asDocumentRoot "/home/youruser/projects/my-web-app". - Restart Apache: Apply the changes by running
sudo systemctl restart apache2.
Once your files are in the native Linux filesystem, Apache serves them directly from the ext4 partition. This eliminates the SMB translation layer, resulting in near-native speed for static asset delivery. You can verify the improvement by checking the network tab in your browser's developer tools; response times should drop significantly.
Verifying the Fix
To confirm that your files are no longer being served from the Windows mount, check the process working directory. Inside your WSL terminal, run pwd while in your project folder. It should start with /home/ or /var/www/, not /mnt/. Additionally, you can use stat on a sample file to see its inode number. Files on /mnt/c will have different inode characteristics compared to native ext4 files.
Common Pitfalls and Alternatives
Sometimes users attempt to symlink their Windows folders into the Linux environment. While this works for reading, it does not solve the I/O latency issue because the underlying data still resides on the NTFS drive. Symlinks merely provide a convenient path; they do not change the physical location of the data. Therefore, symlinking to /mnt/c/... will continue to suffer from the same delay problems.
If you absolutely must keep your source code in Windows for version control reasons, consider using a build pipeline. You can write a script that copies compiled, minified assets from /mnt/c/ to /var/www/html/ only after the build process completes. This reduces the number of small file accesses during runtime to a minimum, mitigating the latency impact. However, for active development with hot-reloading, native Linux storage remains the superior choice.
Another consideration is the security context. When moving files, ensure that the Apache user (www-data) has read permissions. You may need to adjust ownership using chown -R www-data:www-data /home/youruser/projects/my-web-app to prevent permission errors after the migration.
Frequently Asked Questions
Can I use a symbolic link to fix the speed issue?
No, symbolic links do not improve performance because they still point to files stored on the Windows NTFS filesystem. The latency comes from the SMB protocol overhead, which persists regardless of how you access the path. You must physically move the files to the Linux ext4 partition to gain speed benefits.
Why does my HTML load but my CSS fails to apply?
This happens because browsers often cache HTML differently than static assets like CSS and JavaScript. If the initial HTML loads quickly from a cached state, subsequent requests for CSS might hit the slow WSL-to-Windows translation layer. This discrepancy makes it look like only the stylesheets are failing, while the structure appears correct.
Is there a way to speed up WSL without moving files?
There is no official setting to disable the SMB translation overhead for mounted drives. Some users experiment with WSLg or specific registry tweaks, but these do not address the core I/O bottleneck. Moving your project to the native Linux filesystem is the only supported and effective solution for high-performance web development.
Will moving my project break my Git repository?
Git repositories work perfectly fine in the Linux filesystem. In fact, Git operations are generally faster on ext4 than on NTFS mounts. You can initialize a new repo in your new Linux directory or clone an existing one there. Just ensure you update your remote URLs if you changed the branch structure, though typically they remain identical.
How do I handle database connections after moving?
If your web app connects to a database running in WSL (like MySQL or PostgreSQL), the connection string usually remains unchanged as long as both the app and the DB are now in the Linux filesystem. If the database was on Windows, you may need to install it inside WSL or configure WSL to connect to the Windows instance securely, though running the DB natively in WSL is recommended for consistency.
Mounting Windows Folder in WSL (Debian) using fstab provides additional context on how Windows directories are handled in WSL environments.