@procore/cdn

Resolve the procore CDN

Usage no npm install needed!

<script type="module">
  import procoreCdn from 'https://cdn.skypack.dev/@procore/cdn';
</script>

README

Resolve Procore CDN

Motivation

Browsers only allow 6 current requests to the same domain. In order to overcome this restriction procore has 4 subdomains for fastly. This helper function will alternate between the subdomains in a sequence of 0-3 by default. The results are memoized, the same string will result with the same value.

Usage

cdn(numberOfDomains: number) {
  return cached(bgImg: string)
    return string
}

Example

import _cdn from '@procore/cdn';
import testImg from './test.png';
import bgImg from './bg.jpg';

const cdn = _cdn(4)

const App = () => {
  return (
    <div>
      <img src={cdn(testImg)} /> 
      /*
        https://procore-production-assets0.global.ssl.fastly.net/22028741.png
      */
      <div style={{ backgroundImage: `url(${cdn(bgImg)})`} />
      /*
        <div style="background-image: url(https://procore-production-assets1.global.ssl.fastly.net/03852981.jpg)></div>
      */
    </div>
  )
}