Home  >  Article  >  Web Front-end  >  Why Can\'t I Access CSS Rules from Local Files in Chrome 64?

Why Can\'t I Access CSS Rules from Local Files in Chrome 64?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-01 14:28:29155browse

Why Can't I Access CSS Rules from Local Files in Chrome 64?

Cannot Access CSS Rules from Local CSS File in Chrome 64: A Case of CORS and Security

As Chrome 64 enforces a stricter Cross-Origin Resource Sharing (CORS) policy, developers now face restrictions in accessing CSS rules from local CSS files. This issue stems from the incongruity between Chrome's recent stance and the practices deemed acceptable by other browsers.

The Problem

The issue arises when attempting to access CSS rules from astylesheet loaded from the local file system. This action triggers a CORS error due to the variance in security origins between the HTML document and the CSS file. In Chrome 64 and subsequent versions, this behavior has been brought in line with the stipulations set forth in the CSS Object Model (CSSOM) specification.

Solutions

To circumvent this issue, developers have employed various workarounds:

  • Deploying the website or testing it locally using a development server enables the browser to treat it as having the same origin as the CSS file, thereby satisfying the CORS policy.
  • Using alternative browsers like Internet Explorer, Microsoft Edge, or Firefox, which have not yet implemented the stricter enforcement of CORS for CSS rules.
  • Invoking Chrome with the --allow-file-access-from-files flag, which temporarily disables the stricter CORS policy and дозволяет access to local CSS rule information.

TL;DR

Developers need to rely on local development servers or alternative browsers to access CSS rules from local CSS files while adhering to the new security measures implemented in Chrome 64. This limitation highlights the importance of same-origin policies and the need for secure web development practices.

The above is the detailed content of Why Can\'t I Access CSS Rules from Local Files in Chrome 64?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn