Content-Security-Policy: prefetch-src directive
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Chỉ thị prefetch-src trong HTTP Content-Security-Policy (CSP) chỉ định các tài nguyên hợp lệ có thể được tải trước hoặc kết xuất trước.
| Phiên bản CSP | 3 |
|---|---|
| Loại chỉ thị | Fetch directive |
Dự phòng default-src |
Có. Nếu chỉ thị này vắng mặt thì trình duyệt sẽ tìm kiếm chỉ thị
default-src.
|
Cú pháp
Content-Security-Policy: prefetch-src 'none';
Content-Security-Policy: prefetch-src <source-expression-list>;
Chỉ thị này có thể nhận một trong các giá trị sau:
'none'-
Không có tài nguyên nào thuộc loại này được tải. Dấu nháy đơn là bắt buộc.
<source-expression-list>-
Danh sách các giá trị biểu thức nguồn phân cách bằng khoảng trắng. Tài nguyên thuộc loại này có thể được tải nếu chúng khớp với bất kỳ biểu thức nguồn nào. Đối với chỉ thị này, các giá trị biểu thức nguồn sau đây có thể áp dụng:
Ví dụ
>Tài nguyên prefetch không khớp với tiêu đề
Với một trang có Content Security Policy sau:
Content-Security-Policy: prefetch-src https://example.com/
Các lần tải cho mã sau sẽ trả về lỗi mạng vì các URL được cung cấp không khớp với danh sách nguồn của prefetch-src:
<link rel="prefetch" href="https://example.org/" />
<link rel="prerender" href="https://example.org/" />