How can I extract only the used CSS on a given web page and have that combined into a separate style sheet?

后端 未结 6 1729
梦毁少年i
梦毁少年i 2020-12-13 14:32

I have a site whose stylesheets are becoming overwhelming, and a full 50% to 90% or so is not used on certain pages. Rather than have 23 separate blocking CSS sheets, I\'d

6条回答
  •  天涯浪人
    2020-12-13 15:30

    If you wanted, you could try to build a script that runs on a (non-production) server that goes through every css rule, removes it from the stylesheet, loads the page using something like phantomjs, and checks to see if anything changed from the last time it loaded the page. If so, then put the css rule back, if not, then leave it out and move on to the next rule. It would take a while to run, but it would work. You would also have to setup an instance of your server that does not use caching for it to run on.

提交回复
热议问题