Title: Preload JavaScript files [not working]
Last modified: June 24, 2025

---

# Preload JavaScript files [not working]

 *  Resolved [Peter Duchnovsky](https://wordpress.org/support/users/pdux/)
 * (@pdux)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/preload-javascript-files-not-working/)
 * Hi,
 * I found out that the preload feature does not work, because you are not setting
   crossorigin
 * Error from console:
 * (index):524 A preload for ‘xxxxxxxx’ is found, but is not used because the request
   credentials mode does not match. Consider taking a look at crossorigin attribute.
 * I fixed it on my site using simple snippet but it would be great if you could
   fix this on your end.
 *     ```wp-block-code
       <?phpadd_action('init', function () {ob_start('fix_all_crossorigin_tags');});function fix_all_crossorigin_tags($html) {// Fix <link rel="preload">$html = preg_replace_callback('#<link\s+[^>]*rel=["\']preload["\'][^>]*>#i',function ($matches) {$tag = $matches[0];if (stripos($tag, 'crossorigin') === false) {$tag = preg_replace('/\/?>$/', ' crossorigin="anonymous">', $tag);}return $tag;},$html);// Fix <script src="...">$html = preg_replace_callback('#<script\s+[^>]*src=["\'][^"\']+["\'][^>]*>#i',function ($matches) {$tag = $matches[0];if (stripos($tag, 'crossorigin') === false) {$tag = preg_replace('/<script\s+/i', '<script crossorigin="anonymous" ', $tag);}return $tag;},$html);return $html;}
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Support [Damilare](https://wordpress.org/support/users/deabiodun/)
 * (@deabiodun)
 * [11 months ago](https://wordpress.org/support/topic/preload-javascript-files-not-working/#post-18528921)
 * Hi [@pdux](https://wordpress.org/support/users/pdux/).
   Glad to see that you’ve
   found a solution for your use case.Your suggestions are duly noted and will be
   put into consideration.
 * Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Preload JavaScript files [not working]’ is closed to new replies.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Damilare](https://wordpress.org/support/users/deabiodun/)
 * Last activity: [11 months ago](https://wordpress.org/support/topic/preload-javascript-files-not-working/#post-18528921)
 * Status: resolved