Recently I got struck with a major issue of page load time with one of my projects developed using Yii2. The issue is regarding assets management. I have site.css, bootstrap.css, and other css from extensions used, along with site.js, bootstrap.js and js files from extensions used being loaded with each page. I know by using different AppAsset i can manage them a bit but still there remains a lot of unused css and js. I have researched over the internet and found great deal of ways to manage css and js file. Like minify, unusedcss, etc.
But I am looking for another way for it.
I want to know if there is any tool or any pattern that can be used to organise my CSS (both external and internal) and JS files (both external and internal) in such a manner that I can manage them on per page basis. And then only css/js which is used in page is added in the file (i.e. file is created on the fly) and send over to browser.
For example, suppose i have some custom css file with 500 css rules in one file named site.css and a bootstrap css file. My homepage uses about only 100 css rules from site.css, along with table and row classes only from bootstrap.css. What I want is that when a request is made for my website homepage then the css gets complied (or say wrapped) with only the used rules and send over with the response. And same goes of all the pages in my website. Each page having it's uniquely generated css file being sent over to browser. Also I want the same scenario with my JS code.
Has any one tried to achieve something like this? And if yes, then please share...
Thanks in advance