peterbe/mincss

mincss gets confused by relative URLs

Opened this issue · 1 comments

I am trying to use mincss to create a CSS file containing the subset used by my site.
However, the same CSS file is linked by different pages using different relative links (../foo.css and ../../foo.css) which means mincss sees it as two different things.

I am using this script to try and analize what mincss can do:

import os
import sys

output_folder = os.path.abspath(sys.argv[1])
from mincss.processor import Processor
p = Processor()
urls = []
for root, dirs, files in os.walk(output_folder):
    for f in files:
        if not f.endswith('.html'):
            continue
        url = os.path.join(output_folder, root, f)
        urls.append(url)

p.process(*urls)
for inline in p.links:
    print "===>", inline.href, len(inline.before), len(inline.after)

And here is it's output:

===> ../../assets/css/bootstrap-responsive.min.css 16849 3251
===> ../assets/css/bootstrap-responsive.min.css 16849 3251
===> assets/css/bootstrap-responsive.min.css 16849 3251
===> ../../assets/css/bootstrap.min.css 106059 14737
===> ../assets/css/bootstrap.min.css 106059 14737
===> assets/css/bootstrap.min.css 106059 14737
===> ../../assets/css/code.css 3670 2114
===> ../assets/css/code.css 3670 2114
===> assets/css/code.css 3670 2114
===> ../../assets/css/colorbox.css 6457 774
===> ../assets/css/colorbox.css 6457 774
===> assets/css/colorbox.css 6457 774
===> ../../assets/css/rst.css 6559 2581
===> ../assets/css/rst.css 6559 2581
===> assets/css/rst.css 6559 2581
===> ../../assets/css/theme.css 1287 1061
===> ../assets/css/theme.css 1287 1061
===> assets/css/theme.css 1287 1061

It's perfectly possible that I am using mincss wrong, of course :-)

Apparently there is no support for multiple pages in mincss, which kind of negates the point of the tool in real life. What you see is probably the sum of every css linked in your pages, whatever they're duplicated or not.