title: How to host my SPA? Make example.com/spa lead to CDN?
body: <h1>Current state</h1>
  
  <p>I have an existing SPA application that runs against a backend server.</p>
  
  <p>I have Apache being setup on my production server in the following way:</p>
  
  <ul>
  <li>DNS example.com points to my production server. There is Apache with proper SSL configuration for my domain</li>
  <li>example.com/frontend leads to SPA files (js/css/...) that are deployed in a folder of my server</li>
  <li>example.com/ leads to my backend which runs on the same server</li>
  </ul>
  
  <h1>What I'd like to do</h1>
  
  <p>I'm trying to deploy my frontend assets to a CDN. There are many options here, but I'm not looking for advices on which one to choose.</p>
  
  <h1>Problem</h1>
  
  <p>If I'm deploying my app to a CDN, files won't be hosted on my production server anymore. So I'll have my backend on example.com, and SPA on myapp.cdn.com</p>
  
  <p>As far as I know it's not possible at the DNS level to make example.com/cdn points to the CDN files. At best I can create another domain cdn.example.com and make it point to myapp.cdn.com but unfortunatly it's not possible in my case...</p>
  
  <p>There is an inconsistent behavior in Safari History API that other browsers don't have. </p>
  
  <p>My index html page is served by my backend server (<a href="https://example.com/" rel="nofollow">https://example.com/</a>, and set as base url my frontend url (<a href="https://example.com/frontend" rel="nofollow">https://example.com/frontend</a>). It currently works fine in all browsers because it's the same domain.</p>
  
  <p>In Safari, if you set a base url of a different domain than the backend base url (using for example <a href="https://frontend.example.com/" rel="nofollow">https://frontend.example.com/</a> as base url instead of <a href="https://example.com/frontend" rel="nofollow">https://example.com/frontend</a>), then there are security exceptions that prevent my app to use HMTL5 History API normally.</p>
  
  <h1>What I'm looking for</h1>
  
  <p>I already know some alternative options, like serving my index.html page directly in the frontend, or not using a base url. Not looking for such kind of solutions at the moment (even if I'm considering them for long terme changes)</p>
  
  <p>What is the best way, on the same domain as my backend server (example.com), to make a path (like example.com/cdn) points to my CDN files? </p>
  
  <p>I'm looking for a production-ready solution, where performance remains correct, and my CDN capabilities still kicks in (etags caching, HTTP2...)</p>
  
  <p>I think my Apache server could eventually receive all requests on /cdn and issue permanent redirects to the CDN domain. Even if it involves an additional roundtrip for the first service, I would be ok with it as long as it's only the first time. Does it look like a production-ready option to you? Is there any decent alternative?</p>