Discover Centmin Mod today
Register Now

Nginx Please advice the correct syntax for Nginx preload and preconnect

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by rdan, Oct 9, 2019.

  1. rdan

    rdan Well-Known Member

    4,671
    1,121
    113
    May 25, 2014
    Ratings:
    +1,663
    Local Time:
    10:37 PM
    Mainline
    10.2
    My current config:

    Code:
    http2_push_preload on;
    
    add_header Link "<https://cdn.domain.com/styles/fonts/roboto-v20.woff2>; as=font; type=font/woff2; crossorigin=anonymous; rel=preload";
    
    add_header Link "<https://cdn.domain.com>; rel=preconnect; probability=1.0";
    
     
  2. eva2000

    eva2000 Administrator Staff Member

    41,724
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:37 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    preload doesn't need the type specified example

    Code (Text):
    add_header Link '<https://fonts.googleapis.com>; rel=preconnect; crossorigin; probability=1.0;';
    add_header Link '<https://fonts.gstatic.com/s/roboto/v20/KFOmCnqEu92Fr1Mu4mxK.woff2>; as=font; crossorigin=anonymous; rel=preload;';
    

    Also for Nginx HTTP/2 Server Push read the proper way to do it conditionally so that it's browser cache aware and only does HTTP/2 Server Push on first vistors and lets browser cache serve subsequent visits Nginx - Nginx HTTP/2 Server Push Finally Supported
     
  3. rdan

    rdan Well-Known Member

    4,671
    1,121
    113
    May 25, 2014
    Ratings:
    +1,663
    Local Time:
    10:37 PM
    Mainline
    10.2
    Thanks Eva.
    Header is added in most pages, but some pages don't have it like XenForo 404 pages.
    So what exact location on Nginx config I must place this to cover all request except static files?
     
  4. eva2000

    eva2000 Administrator Staff Member

    41,724
    9,395
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,431
    Local Time:
    12:37 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Xenforo 404 would be php generated so most likely needed in your php.conf include file for location for *.php files - though that could make duplicate headers in your location contexts so you'd need to work that out. Though I wouldn't bother with preload for 404 pages to be honest
     
    • Like Like x 1
  5. EckyBrazzz

    EckyBrazzz Active Member

    699
    139
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +258
    Local Time:
    11:37 AM
    1.17.x Cluster
    10.3.x Cluster & Redis
    Reading my issue

     
  6. EckyBrazzz

    EckyBrazzz Active Member

    699
    139
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +258
    Local Time:
    11:37 AM
    1.17.x Cluster
    10.3.x Cluster & Redis
    @eva2000 How can we get this to work on all domains, not only just one.
    There are many files in domains that we want to have with Push Support like the image below (yours)
    6289_cache-aware-http2-push.gif