Home > Article > Web Front-end > How to Securely Include External CSS and JS Files via HTTPS?
Secure Inclusion of External CSS and JS Files via HTTPS
When incorporating external CSS and JS files into your website, it's important to ensure that they're served securely when the parent page is accessed via HTTPS. Browsers often display warnings if unsecured content is loaded onto HTTPS pages.
To resolve this issue, utilize protocol-relative paths. Instead of specifying the full URL, including the protocol (e.g., http), use double forward slashes (//).
Example:
Instead of:
<link rel="stylesheet" href="http://example.com/style.css"> <script src="http://example.com/script.js"></script>
Use:
<link rel="stylesheet" href="//example.com/style.css"> <script src="//example.com/script.js"></script>
By using protocol-relative paths, the browser will automatically fetch the external content using the same protocol as the parent page. This ensures that all content is loaded securely when the page is accessed via HTTPS.
The above is the detailed content of How to Securely Include External CSS and JS Files via HTTPS?. For more information, please follow other related articles on the PHP Chinese website!