• Resolved Brad

    (@saskso)


    Is there documentation for any filters exposed by W3TC and could I use those to add a global preconnect http header for my image CDN? Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @saskso,

    Unfortunately there is no documentation for filters exposed by W3TC, but we are happy to provide any advice we can.

    What exactly are you referring to and trying to achieve by setting up a global preconnect http header for your image CDN?

    Thread Starter Brad

    (@saskso)

    I want a preconnect http header to be sent that tells the browser to preconnect to my image CDN so images load faster. It is part of the Link part of the http header. With cached pages if I try to use another plugin that modifies HTTP headers it doesn’t work since W3TC controls the cache pages and bypasses WordPress and the plugins. So, I was hoping there is a W3TC filter or some other way to tell W3TC to add a http link header specifying my image CDN. The link http header would look something like below:
    link: <https://res.cloudinary.com>; rel=preconnect

    Thank you.

    • This reply was modified 6 years, 7 months ago by Brad.
    Thread Starter Brad

    (@saskso)

    As a workaround (but would still prefer a filter if there is one as discussed at the end below) you can add a link header to the .htaccess file in the page cache directory for w3tc.

    As a pre-caution, I surrounded it by the files directive because I wanted to be sure it didn’t get added to anything but html pages but probably not necessary since there are no images or scripts etc., in the page cache dir…..

    <Files ~ "\.(html|html_gzip|html_br)$">
    Header add Link "</wp-includes/js/jquery/jquery.js>; rel=preload; as=script"
    </Files>

    I also tried Header add Link “</wp-includes/js/jquery/jquery.js>; rel=preload; as=script” and saw it pushed in Chrome.

    I am not quite marking this as resolved yet because I would like to know from W3TC support if there is a filter to add a http header. If there was a filter then I could use code to push for example a CSS or JS file that changes often like say the ones from the Autoptimize plugin. I cannot push those with a .htaccess header because they change.

    So, is there a filter to add a http header with W3TC? If not, it would be nice to add one that other plugins could hook into since the caching bypasses everything and won’t include any headers other plugins try to set or that I set functions.php.

    Thank you.

    Edit: fixed editor malforming link code I used by using code tag, I think….

    • This reply was modified 6 years, 7 months ago by Brad.
    • This reply was modified 6 years, 7 months ago by Brad.
    • This reply was modified 6 years, 7 months ago by Brad.

    Hi @saskso, thank you for following up with this issue.

    When using Disk: Enhanced as your caching method, the headers are iterated over and added within https://github.com/W3EDGE/w3-total-cache/blob/master/Cache_File_Generic.php#L100 which would need to be extended to allow the functionality you intend, such as including or excluding specific items from being added to the header.

    Caching methods other than Disk: Enhanced do not have this limitation, so I would suggest to use an alternative method if possible.

    I have also created a feature suggestion with the developers to add your requested filter functionality in a future version.

    I hope that this information helps you make the customizations you need to work with your image CDN and please let us know if there is anything else that we can do to assist!

    Thread Starter Brad

    (@saskso)

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘W3TC Filter Docs’ is closed to new replies.