Search code examples
javascriptcdn

Does CDN know which website the client is visiting when fetching jquery.min.js or other resource from CDN?


Can CDN create some kind of statistics by tracking visitors of my site or they download needed libraries without sharing the URL of the page they visit ?


Solution

  • Yes, they can use the referer header field:

    The HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage (i.e. the URI or IRI) that linked to the resource being requested. By checking the referrer, the new webpage can see where the request originated.

    The field is part of the request header which could look like this, for example, reloading this page will show that this link to googleapis (see console F12 and the network tab):

    http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
    

    Sent this request header:

    Host: ajax.googleapis.com
    User-Agent: Mozilla/5.0 (...)
    Accept: */*
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    DNT: 1
    Referer: http://stackoverflow.com/questions/30743915/does-cdn-know-which-website-the-client-is-visiting-when-fetching-jquery-min-js-o
    Connection: keep-alive
    Pragma: no-cache
    Cache-Control: no-cache
    

    Reporting which site it came from using the referer:

    Referer: http://stackoverflow.com/questions/30743915/does-cdn-know-which-website-the-client-is-visiting-when-fetching-jquery-min-js-o