A 404 error when loading scripts in IIS 10 on Windows 10 typically stems from incorrect MIME type mappings or improper file path resolution. By configuring the server to recognize JavaScript and CSS extensions, you ensure that static assets are served correctly rather than triggering a "Not Found" response. This guide details the precise steps to resolve these configuration issues within the IIS Manager interface.
Understanding the Root Cause
When Internet Information Services (IIS) receives a request for a file, it checks its internal database of MIME types to determine how to handle the content. If a specific file extension, such as
.js for JavaScript or
.css for stylesheets, is not mapped to a valid MIME type, IIS may refuse to serve the file. In many default configurations, especially after fresh installations or updates, these mappings might be missing or corrupted. Consequently, the browser receives a 404 status code, interpreting the lack of a valid content handler as an absence of the resource.
Another common cause involves the physical location of the files relative to the web root. If your application structure places scripts in subdirectories without proper virtual directory configuration, IIS might fail to resolve the path. Additionally, URL Rewrite rules can inadvertently block access to certain file types if they are configured too restrictively. Before diving into complex rewrites, it is crucial to verify that the basic static content serving capabilities are enabled and that the MIME types are correctly defined.
Verifying Static Content Feature Installation
The first step in troubleshooting is ensuring that the core feature required to serve static files is installed on your Windows 10 machine. IIS does not include all features by default; administrators must explicitly enable them during setup or via Server Manager.
To check this, open the
Server Manager and navigate to
Roles >
Web Server (IIS). Click on
Add Role or Feature and proceed through the wizard until you reach the
Features section. Look for
Static Content under the
Common HTTP Features group. If this checkbox is unchecked, select it and complete the installation. Without this feature, IIS cannot process requests for HTML, images, or scripts, leading directly to 404 errors for any static asset.
If you prefer using PowerShell, you can verify the installation state by running:
Get-WindowsFeature Web-Static-Content
The output should show
Installed : True. If it returns
False, install it using:
Install-WindowsFeature Web-Static-Content
After installation, restart the IIS service by running
iisreset in the command prompt to apply changes.
Configuring MIME Types in IIS Manager
Once the static content feature is active, the next critical step is mapping the file extensions to their corresponding MIME types. This tells IIS exactly what kind of data is being sent to the client.
Open
IIS Manager and select your server node or the specific site causing the issue. Double-click on the
MIME Types icon in the Features View. Scroll through the list to find entries for
.js and
.css. The standard MIME type for JavaScript is
application/javascript or
text/javascript, and for CSS, it is
text/css.
If these entries are missing, click
Add... on the right-hand Actions pane. Enter the file name extension with a dot (e.g.,
.js) and the correct MIME type. Repeat this for any other custom script extensions you use, such as
.ts for TypeScript or
.map for source maps. Ensure that there are no duplicate entries with conflicting types. Saving these changes allows IIS to serve these files dynamically based on their extension.
For sites hosted on different domains or subdomains, you may need to configure MIME types at the site level rather than the global server level to avoid conflicts with other applications. Always test after making changes by refreshing your browser's developer tools network tab to confirm the status code changes from 404 to 200.
Checking File Paths and Virtual Directories
Even with correct MIME types, a 404 error can occur if IIS cannot locate the physical file. Verify that the file exists in the expected directory structure. Common mistakes include case-sensitivity issues, although Windows file systems are generally case-insensitive, some deployment pipelines may alter casing unexpectedly.
Check if your scripts are located in a subfolder that requires a virtual directory. In IIS Manager, right-click your site and select
Add Virtual Directory. Assign an alias (e.g.,
scripts) and point it to the physical path containing your JS files. Update your HTML references to use this alias, such as
/scripts/app.js.
Additionally, inspect the
URL Rewrite module if you have active rules. A rule might be redirecting or blocking requests to static files. Disable rewrite rules temporarily to see if the scripts load correctly. If they do, adjust the rule conditions to exclude static file extensions like
\.js$ or
\.css$ from processing.
This issue shares similarities with general connectivity problems seen in other Windows 10 services, where underlying system components fail to communicate properly due to misconfiguration. For more insights on resolving broader Windows 10 service errors, you might find our article on
Unexplained Slowness on Windows 10 PC helpful, as it covers diagnostic techniques applicable to various service failures.
Frequently Asked Questions
Why do I get a 404 for .js files but not .html?
HTML files are usually handled by the default document handler or generic static content processing which is often pre-configured. JavaScript files require explicit MIME type mappings in many IIS versions. If the mapping is missing, IIS treats the request as invalid or unknown, resulting in a 404 error instead of serving the text content.
Can I set MIME types via web.config instead of IIS Manager?
Yes, you can add MIME types directly in your
web.config file under the
<system.webServer> section. Use the
<staticContent> element to define new mappings. This method is useful for portability, ensuring that the configuration travels with your application code rather than relying on server-level settings.
Does restarting IIS clear the cache?
Running
iisreset stops and starts all IIS services, which effectively clears the configuration cache and reloads all modules. This is necessary after changing MIME types or installing new features to ensure the changes take immediate effect without requiring a full server reboot.
How do I troubleshoot if MIME types are correct but still 404?
If configurations are correct, check the physical file permissions. Ensure the IIS user account (
IUSR or the application pool identity) has read access to the folder containing the scripts. Lack of NTFS permissions will result in a 404 or 403 Forbidden error depending on the specific failure mode.
Are there security risks in adding broad MIME types?
Adding overly permissive MIME types can expose your server to cross-site scripting (XSS) attacks if users can upload files with executable extensions. Always restrict MIME types to only those required by your application. Avoid mapping dangerous extensions like
.exe or
.bat to web-accessible directories unless absolutely necessary and secured.