To optimize your code in plain Javascript, I recommend segregating CSS styles into different files for each domain. Create two separate files - one for be
and one for nl
, containing only the unique style attributes.
somefilename_be.css
{
body: 'green';
}
somefilename_nl.css
{
body: 'red';
}
For common styling elements, maintain a shared file such as common.css
.
Based on the domain, you can conditionally load the appropriate CSS file.
if (window.location.host.split('.')[1] === "be")
document.write('<link rel="stylesheet" href="somefilename_be.css" />');
else
document.write('<link rel="stylesheet" href="somefilename_nl.css" />');
For JS Frameworks (React, Angular, Vue, Next, Svelte)
if (window.location.host.split('.')[1] === "be")
import('somefilename_be.css'));
else
import('somefilename_nl.css'));