Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload Links: Javascript siteUrl variable is using WordPress Address and not Site Address #3071

Closed
tombonez opened this issue Sep 7, 2020 · 5 comments · Fixed by #3104
Closed
Assignees
Labels
effort: [XS] < 1 day of estimated development time module: preload priority: low Issues that can wait type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@tombonez
Copy link

tombonez commented Sep 7, 2020

The siteUrl variable output in the Preload Links Javascript code is using the WordPress Address and not the Site Address, so whilst using WordPress in a sub-directory environment (e.g. Bedrock) this variable will output as https://example.com/wp instead of https://example.com stopping preloading links from working (if I understand the Javascript code correctly).

Steps to reproduce

  1. Install WordPress in a sub-directory environment (e.g. Bedrock).
  2. Enable link preloading under WP-Rocket->Preload.
  3. Inspect the siteUrl variable output as inline Javascript in the cached code.

Expected behavior

The siteUrl variable to output the Site Address (using home_url() or similar) so that all links under the website can be preloaded on hover.

Additional context

The code in question is the following:

var RocketPreloadLinksConfig = {"excludeUris":"\/(.+\/)?feed\/?.+\/?|\/(?:.+\/)?embed\/|\/(index\\.php\/)?wp\\-json(\/.*|$)|\/wp-admin\/|\/logout\/|\/wp-login.php","usesTrailingSlash":"1","imageExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif","fileExt":"jpg|jpeg|gif|png|tiff|bmp|webp|avif|php|pdf|html|htm","siteUrl":"https:\/\/example.com\/wp","onHoverDelay":"100","rateThrottle":"3"};

And I believe the code that needs modifying is here:

$config = [
	'excludeUris'       => $this->get_uris_to_exclude( $use_trailing_slash ),
	'usesTrailingSlash' => $use_trailing_slash,
	'imageExt'          => $images_ext,
	'fileExt'           => $images_ext . '|php|pdf|html|htm',
	'siteUrl'           => site_url(),
	'onHoverDelay'      => 100, // milliseconds. -1 disables the "on hover" feature.
	'rateThrottle'      => 3, // on hover: limits the number of links preloaded per second.
];
@arunbasillal
Copy link
Contributor

arunbasillal commented Sep 7, 2020

@tombonez Thanks for the detailed report. In case you haven't noticed, as an interim solution you can take advantage of the rocket_preload_links_config filter.

@hellofromtonya Can you please take a look when you have a chance?

@tombonez
Copy link
Author

tombonez commented Sep 8, 2020

Thanks @arunbasillal that's definitely good to know 😃

@hellofromtonya
Copy link
Contributor

@arunbasillal What do you think of this in the next minor release?

@arunbasillal arunbasillal added this to the 3.7.1 milestone Sep 9, 2020
@arunbasillal arunbasillal added needs: grooming priority: low Issues that can wait type: bug Indicates an unexpected problem or unintended behavior module: preload labels Sep 9, 2020
@arunbasillal
Copy link
Contributor

@hellofromtonya For sure 👍

@arunbasillal arunbasillal modified the milestones: 3.7.1, 3.7.2 Sep 11, 2020
@viobru
Copy link
Contributor

viobru commented Sep 16, 2020

@hellofromtonya hellofromtonya added effort: [XS] < 1 day of estimated development time and removed needs: grooming labels Sep 16, 2020
@Tabrisrp Tabrisrp modified the milestones: 3.7.2, 3.7.1 Sep 16, 2020
Tabrisrp pushed a commit that referenced this issue Sep 18, 2020
@Tabrisrp Tabrisrp mentioned this issue Sep 30, 2020
Tabrisrp added a commit that referenced this issue Sep 30, 2020
- 3rd party compatibility: Automatic compatibility with DreamPress hosting (#2789)
- Enhancement: Add additional auto-exclusion from defer JS and combine JS  to prevent issues
- Enhancement: Add index file inside WP Rocket generated directories to prevent direct access to them (#3057)
- Bugfix: Update trustpilot pattern for delay JS to prevent JS errors (#3080)
- Bugfix: Remove Google recaptcha from delay JS default list (#3075)
- Bugfix: Added pixel caffeine JS script to delay JS default list to prevent JS errors (#3088)
- Bugfix: Update preload links configuration to prevent an issue when WordPress is installed in a sub-directory (#3071)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [XS] < 1 day of estimated development time module: preload priority: low Issues that can wait type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
5 participants