Here is a simple demonstration of a node file proxy. This proxy would sit between your site and third-party scripts.
Many marketing providers and plugin providers provide embeddable scripts, but many don't use a Content Delivery Network (CDN) so their response time is slow.
They also don't cache their scripts because they need to update them from time to time (this is for Facebook pixel, Google and other big guys too). This can slow down the site loading and create low Chrome Lighthouse scores and general lag.
Beta
$ git clone git@github.com:camsjams/node-file-proxy.git
$ cd node-file-proxy
$ npm install
PORT: sets port - defaults to 3113
$ node index.js
# (or npm start but lower overhead with above)
http://localhost:3113/f?url=YOUR_URL_HERE
http://localhost:3113/f?url=http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
Security wise you would probably want to whitelist referral domains and request URL domains.
- Whitelist the request's origin to only permit apps you trust (via domains)
- Whitelist the request's desired file url to only permit file downloads from domains you trust (Google Analytics, Facebook, etc)
This service responds back with the basic expiration headers that most CDNs can understand, refer to documentation and CDN dashboard to ensure all headers are present and a cache HIT
occurs on your CDN.
Your CDN should point to the proxy server, and this relationship will occur:
- The app or browser sends a request to your CDN. https://your-cdn-domain.com/f?url=http://other-domain.com/file.js
- Internally, the CDN will request your proxy server at
f?url=http://other-domain.com/file.js
- The server (this project code) will serve the response, using the expiration headers sent from your proxy server.