I have a project with 6 views (html). Each of those views has a corresponding view model (.js) and a style sheet just for that view (.css)
The aurelia-cli does a wonderful job of recursing through my file free and bundling all the .js and .css files into a couple of files so they can be referenced while reducing page load times and size. So if I have a welcome folder with a welcome.html, welcome.js and welcome.css, I can load the CSS for welcome.html with the following <require from="./welcome.css"></require>
and the CSS will be injected into the <head></head>
tags on page load.
The problem with that is when I navigate to the next view the CSS rules from welcome.html / welcome.css are still within the <head>
tag of the webpage thus still being enforced. After visiting all 6 views in my application I now have 6 <style>
tags within the <head>
tag with all of the rules from all six pages being enforced on every page I go to with no unloading taking place until the page is refreshed. Needless to say after visiting a couple pages the entire site becomes jumbled garbage.
So my questions are
- Why is this a feature
- Am I missing a best practice here?
- Is there a way now to load the css for a page when visited, unload it when navigated away, and load the new pages css in it's place?
If I had a 10 page app with a global stylesheet, bootstrap, animate css, and font awesome, at the end of the day I have 14 conflicting styles injected permanently into the html the rest of the app is injected into.
Any suggestions?