8000 Order is destroyed when merging across multiple pages · Issue #16 · peterbe/minimalcss · GitHub
[go: up one dir, main page]

Skip to content

Order is destroyed when merging across multiple pages #16

Closed

Description

@peterbe

minimalcss will generate minimal CSS payloads for multiple URLs. It then combines them into one final merged version. Suppose you have two URLs with different DOM nodes present.

// pageX.html's minimal CSS
.btn { font-size: 10px }
.btn-default { font-size: 12px }

...and...

// pageY.html's minimal CSS
.btn { font-size: 10px }

First you combine this into one blob of CSS so it becomes:

.btn { font-size: 10px }
.btn-default { font-size: 12px }
.btn { font-size: 10px }

...and run it through csso.minify()
you end up with this:

.btn-default{font-size:12px}.btn{font-size:10px}

Now, in the case of this <button class="btn btn-default"> you end up with a button that is font-size: 10px which is not what you wanted.

Activity

  1. peterbe commented on Feb 5, 2018

    @peterbe
    OwnerAuthor

    Added a blurb about it in the README.

    I'm still wondering if it'd be possible to technically solve this. Probably not. But perhaps there's an opportunity to see what values of selectors change when the second URL comes in. Hard.

  2. ihorsl commented on May 29, 2019

    @ihorsl

    If it is possible to log each css rule line number and filename, than you can merge them according to line number in css file
    page 1
    Line number 100 .btn { font-size: 10px }
    Line number 200 .btn-default { font-size: 12px }

    page 2
    Line number 100 .btn { font-size: 10px }

    Result after merge:

    Line number 100 .btn { font-size: 10px }
    Line number 100 .btn { font-size: 10px }
    Line number 200 .btn-default { font-size: 12px }

  3. leeoniya commented on May 29, 2019

    @leeoniya

    you may find this useful: leeoniya/dropcss#22

  4. leeoniya commented on May 29, 2019

    @leeoniya

    thinking about it a bit more, i think a partial solution might be to get the minimal css per file, then merge all same files before merging others. csso(csso(base1_minimal, base2_minimal), csso(specific.css)). still relies on file ordering though.

    EDIT: nope, this prolly won't work either :(

  5. peterbe commented on May 30, 2019

    @peterbe
    OwnerAuthor

    @ihorsl I think it goes deeper than that. It might work'ish. Suppose it's possible to write something like that it might get it right 90% of the time, but those 10% would be a disaster. I say disaster because the work to untangle it would be really hard. You'd almost have to start over from scratch.

    Remember, something like this minimalcss is probably only needed when you use a CSS framework. If you handcoded all the CSS it'd probably so minimal (no pun intended) that none of this tooling is necessary.

    My point is, we got to be careful so we don't really need to understand what we're optimizing. Otherwise the abstraction will leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0