• Resolved moongear

    (@moongear)


    I have noticed that the generated css files (e.g. /wp-content/litespeed/cssjs/fc01c.css) are not unique for each page. I have both minify and combine set and would expect each page to have its own file.

    This is a problem because I created a local uncss node app and am coming in after the css files are generated (via a cron) and removing the unused css for each of the generated files. When unused css is removed for one page, the inclusion of that same css file on another page results in broken styles due to them having been removed when compared to whatever happened to be the first page tested.

    I have overcome this by creating a custom css file (on the fly), named for the page being loaded and with rules that are unique (e.g. random ::after content on an insignificant element with a height of 0) then enqueueing it.

    While this does force the creation of a minified and combined css for each page, this really isn’t practical and likely isn’t reliable. Is there a setting or other inherit method within the plugin that will achieve this?

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Are these pages loading exact same CSS/JS files ?

    I just did a quick test on StoreFront theme , which in some pages , it loads same generated file , in some pages don’t which they have different JS/CSS

    Best regards,

    Thread Starter moongear

    (@moongear)

    The generated files vary from page to page but only a few files are generated over dozens of pages.

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    When you see different generated file , please attach to URL this query string to view the original file

    /?LSCWP_CTRL=before_optm

    and then to see if they are having exact same JS/CSS file

    if multiple pages uses same set of CSS/JS , then generated CSS/JS should be same

    if pages uses different CSS /JS on each page, then it will generate differente CSS/JS for each pages.

    for example

    page A , page B , page C use 1.js , 2.js , 3.js , this will generate a a.js

    page D uses 1.js 2.js , but no 3.js , then it will get a different generated file , let’s say b.js

    if page E uses 1.js and 3.js , but not 2.js , then it will get , let’s say , 3.js

    and so on , for CSS as well

    Best regards,

    Thread Starter moongear

    (@moongear)

    Thank you for your response. I think perhaps you did not read my original post or you do not understand what I wrote. I fully and completely understand the concept of how the plugin works.

    I want to see different files. My goal is to have a completely separate file generated for every unique URL.

    I do not want them to be shared across multiple URL’s even IF those URL’s load the same CSS files.

    I don’t care about the JS files because in my configuration I am not combining JS. I use JS HTTP/2 Push so combining them is a waste of resources.

    I want seperate CSS files because I am using UNCSS to remove unused CSS from each of them after they are generated by the LS plugin. (I already wrote this above but here it goes…) I cannot rely on this process when the files are shared across multiple URL’s because not all pages, even though they load the same original CSS files, do not utilize all of the rules in the original CSS files. Therefore, if the CSS is stripped of unused CSS based on Page A, then Page B may be missing CSS rules.

    Because of this, Page B/C/D/E/F/G and so on need their own generated CSS file so that UNCSS can strip unused CSS from it based on what rules are used in those particular pages.

    In short, is there a way to FORCE the LS Cache plugin to generate a new combined CSS file for every unique URL?

    Plugin Support Hai Zheng?

    (@hailite)

    Try use / in Separate CCSS Cache URIs as it supports partial match.

    Thread Starter moongear

    (@moongear)

    Thanks, but separate CCSS is not the goal. Seperate CSS is the goal. Additionally, in my instance I am not using CCSS as it is unreliable and bloated. I manually created the CCSS and am including it in the header.php.

    Plugin Support Hai Zheng?

    (@hailite)

    Oh sorry my bad. How did you run the uncss node? I mean, how do you find the page URL for each generated css file? Do you use the mapping data stored in db table litespeed_cssjs? But there isn’t any source URL recorded.

    Plugin Support Hai Zheng?

    (@hailite)

    I am thinking if we give a filter to manipulate the css file name when generating the $filename at https://github.com/litespeedtech/lscache_wp/blob/master/src/optimize.cls.php#L1021-L1025 , will that help?

    Or, if you have better idea, please don’t hesitate to let us know. Thanks.

    Thread Starter moongear

    (@moongear)

    When a unique CSS file is generated for each source URL then the refer column in that table works as expected.

    However, in a hacky case it would not be difficult to derive the hashed file from the last 5 MD5 of the json_encoded SRC + ITEM_TIMESTAMP_PURGE_CSS combination then come at this from another direction. I would do add_action( 'wp', 'interrupt_all_frontend' ) when specific GET vars are present then return the necessary css source list on demand. This would, however, be a pain as it would require running these in advance then saving the results separately somewhere for easy access and constantly testing if option litespeed.optimize.timestamp_purge_css has changed.

    A better solution would be if you update refer with subsequent source URLs.

    Also, would be nice if there was a ON/OFF switch to generate css (or js) for each unique page. Then when ON you could add the uri value in $hash = md5( json_encode( $src ) . $purge_timestamp ) ; perhaps like $hash = md5( json_encode( $src ) . $uri . $purge_timestamp ) ;

    Even better yet… more hooks in your software so people like me can better manipulate/add-to its behavior.

    Edit: I saw your last post regarding the filter after I wrote this. Yes, a filter such as that would be helpful. In that situation, I would apply my methodology making the files unique for each URL.

    • This reply was modified 4 years, 5 months ago by moongear.
    • This reply was modified 4 years, 5 months ago by moongear.
    Plugin Support Hai Zheng?

    (@hailite)

    Please try v3.2.3-rc5 https://github.com/litespeedtech/lscache_wp/commit/ed60c62e6f5787d39a6cf55c0e374ee9fff84cd8

    I added a filter https://github.com/litespeedtech/lscache_wp/commit/ed60c62e6f5787d39a6cf55c0e374ee9fff84cd8#diff-17436992b3f4fa1bda35dae77aa68954R91. You can take that over to pass in any css you want to replace the default one.

    Note: there is a new setting Unique CSS under CSS settings, you need to turn it on to ignore the file max size limit setting.

    Thread Starter moongear

    (@moongear)

    I pulled this today and it looks really good. So far it appears to be working as intended.

    Thank you so much and I will update if anything changes.

    Plugin Support Hai Zheng?

    (@hailite)

    Good to know. Will release v3.2.3 today.

    Thread Starter moongear

    (@moongear)

    Good morning. So, I don’t think this is working quite right. I am going to create a fork and tinker around with it.

    Plugin Support Hai Zheng?

    (@hailite)

    You don’t have to use the filter litespeed_css_serve. If use that filter, the content has to be generated on the fly.

    You can only use the new option Unique CSS. That will give the litespeed_cssjs table one unique CSS per URL. Then you can go through the page using your cron like before to trim the CSS content.

    The way you makes this inspired us. For v3.3, we will give a service (similar to CCSS) to provide foreground and background CSS trim to remove unused CSS.

    Thread Starter moongear

    (@moongear)

    You will be the ONLY service provider that is offering that for WordPress. It is much talked about but nobody is doing it.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Non unique minified/combined css for each page’ is closed to new replies.