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
Add header: Accept-Ranges 'bytes' to super-cache expert mode .htaccess
#27748
Add header: Accept-Ranges 'bytes' to super-cache expert mode .htaccess
#27748
Conversation
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Super Cache plugin:
|
What does "Needs Author Reply" mean? Am I the author or the Authors of this plugin? I'm a bit overwhelmed by all these bots, maybe someone can help? :) |
Thanks for your contribution!
In this case, the author would be you, the author of the PR. As you can see in the checks running below, there are a few things that you will need to fix in your branch before this PR can be merged:
Thank you! |
Thanks @jeherve for your help.
Regarding the linting: Should I run this on the whole monorepo or only on super-cache? Which scripts would I need to run excactly? prettier and phpcs? It would probably be quicker if someone who knows what they are doing would do these things, instead of trying to hold my hand through this 🙏 |
Sorry, I may have wrongly assumed your local setup. What do you get when you run
You do not need to run any scripts for this. You should be able to manually make the changes that are highlighted as errors here:
If that doesn't work out for you, let me know and I'll make the changes in your branch for you. |
Thank you!! I'll try my best. If that's not enough I'll gladly accept your help. |
I just tried merging Here is the result of clicking on "Show Command Output" (sorry, a lot of text):
|
…er-accept-ranges-bytes
Hi @hirasso! Thanks for contributing to Super Cache. I understand that contributing to the Jetpack monorepo can be intimidating :) I appreciate that you've taken the time to get involved. I want to check something about the change you've made here. It looks like you've added the "Accept-Ranges" header to the I don't believe this will affect other resources (e.g.: fonts, images, etc) loaded statically out of your wp-content directory, so I worry that this won't quite do what you're after. Can you tell me a little bit more about your site? Are you using this to preload other documents (I believe browser support for this is sketchy at the moment), or are you aiming to preload static resources such as fonts and images used by your theme? |
First of all, thanks a lot @jeherve for your help with preparing this PR. @thingalon Thank you for your friendly message! I'll try to explain my use case a bit more. I am using quicklink on my site to dynamically prefetch other pages that I'm quite sure the visitor will need. Quicklink will inject
...and can be reused if the request restarts, if I read correctly. While quicklink does quite aggressive prefetching, there are other libraries like https://instant.page/, that prefetch links (inject a
Another snippet from the MDN article:
The html files in the cache folder are static files after all, right? :) Looking forward to hear your thoughts. |
Thanks for the extra context @hirasso. I have some good news for you: we don't need to modify Super Cache to accomplish your goals. Inside
This marks the last line that Super Cache will modify in that htaccess file, so you can add custom code after that - and Super Cache will not overwrite it. So, if you add the following to your
... it should accomplish your goals. Just make sure that you have I don't want to add extra lines to WP Super Cache's default "expert" mode config files to support 3rd party plugins - unless we're absolutely sure it will be of benefit to the majority of our user-base. So I'm afraid I'm going to close this PR without merging it. But I hope the way I've identified for you can help you set your site up the way you want it! 😄 |
Ok @thingalon , I'm sure you have good reasons not to accept every feature request to a plugin like super cache, that is so widely being used. Thank you for your hint towards the possibility to add custom stuff to the Since I am planning to have this feature available on more than one site and I'm sure that I won't remember to put my custom directives in the /**
* Modifies the .htaccess in the WP Super Cache
* directory `wp-content/cache/.htaccess`
*
* @return void
*/
function modify_wpsc_cache_dir_htaccess() {
// Bail early if the .htaccess doesn't exist
$htaccess_path = WP_CONTENT_DIR . '/cache/.htaccess';
if (!file_exists($htaccess_path)) return;
// Make sure `insert_with_markers` is available in WP_CLI
if (!function_exists('insert_with_markers')) {
require_once(ABSPATH . 'wp-admin/includes/misc.php');
}
// Our custom directives
$custom_directives = [
"<IfModule mod_headers.c>",
"Header set Accept-Ranges 'bytes'",
"</IfModule>"
];
// Update the .htaccess file
insert_with_markers(
$htaccess_path,
'my-custom-directives',
$custom_directives
);
}
add_action('wp_cache_cleared', 'modify_wpsc_cache_dir_htaccess'); Maybe it comes in handy for anyone else in the future, who knows 🤷♂️ |
Related thread on the forums: https://wordpress.org/support/topic/add-accept-ranges-header-to-htaccess/
I am making heavy use of link prefetching on one of my websites. In the article about prefetching on MDN they mention, that, if the response header contains Accept-Ranges: bytes, a partially loaded resource can be re-used from the browser cache.
Changes proposed in this Pull Request:
During the generation of the
.htaccess
file for super-caches expert mode, This header directive is being injected:Other information:
Since this PR only targets super-cache, I haven't set-up the full jetpack environment. Just symlinked the plugin to my plugins folder as described and tested the new directive injection manually. Works fine for me.
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Disabling the cache and re-enabling it re-generates the
.htaccess
file and injects the new directive. Before:After: