I have an AngularJS site that is pulling in posts from WordPress via the plugin "WP REST API (WP API)". I am testing a site on both dev and staging subdomains, and the WP API works on both. However, when I visit one domain, and then switch over to another domain immediately afterward, then the dynamically-generated Access-Control-Allow-Origin is "stuck" on the previous domain to make the API calls. It's not until I refresh the page, that the response header updates to the current domain making the request. Here is what it says in the Chrome console:
XMLHttpRequest cannot load http://wp.domain.tld/wp-json/pages/couples. The 'Access-Control-Allow-Origin' header has a value 'http://staging.domain.tld' that is not equal to the supplied origin. Origin 'http://dev.domain.tld' is therefore not allowed access.
How do I fix this?