python - 如何使用 python 分割大型 CSS 文件?

标签 python html css python-3.x

我遇到的问题来自 IE 8 has limits for CSS files 。在我的 Flask 元素中,我的一些 CSS 文件超出了这些限制,并且无法正确渲染。

有谁知道如何使用 Python 拆分 CSS 文件,以便使我的文件满足 IE 8 对 CSS 施加的限制?

最佳答案

这就是我的想法。当然,它必须经过修改才能成为在 SASS 之后运行的命令行工具,或者可能成为 Flask 代码中的某种过滤器。

css = "the contents of your enormous css file"
rules = re.findall(r'[^\{]+\{[^\}]*\}', css, re.MULTILINE)

print 'Number of rules: ', len(rules)

with open('output1.css', 'w') as f:
    f.write('\n'.join(rules[:4096]))
if len(rules) > 4096:
    with open('output2.css', 'w') as f:
        f.write('\n'.join(rules[4096:]))

关于python - 如何使用 python 分割大型 CSS 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32120951/

相关文章:

python - Python 文档中的错误?

php - 在我的网站中发现 opencart 错误

jquery - 使用 Twitter Bootstrap 3 固定导航栏

javascript - 单击按钮后,在单击事件进行时在按钮上显示微调器图标

python - django 警告 urls.W005 URL 命名空间不唯一

python - "Installing From Source"在 Anaconda 环境中

html - 粘性页脚中的 hr 问题

css - 如何创建输出集中式 css 规则的 less mixin?

python - 在 Python 中引用相同对象的对象列表列表

javascript - 如何在 Html/css 中在新窗口(而不是新标签页)中打开链接