当前位置: X-MOL 学术ACM Trans. Program. Lang. Syst. › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
CSS Minification via Constraint Solving
ACM Transactions on Programming Languages and Systems ( IF 1.3 ) Pub Date : 2019-06-19 , DOI: 10.1145/3310337
Matthew Hague 1 , Anthony W. Lin 2 , Chih-Duo Hong 3
Affiliation  

Minification is a widely accepted technique that aims at reducing the size of the code transmitted over the web. This article concerns the problem of semantic-preserving minification of Cascading Style Sheets (CSS)—the de facto language for styling web documents—based on merging similar rules. The cascading nature of CSS makes the semantics of CSS files sensitive to the ordering of rules in the file. To automatically identify rule-merging opportunities that best minimise file size, we reduce the rule-merging problem to a problem concerning “CSS-graphs,” i.e., node-weighted bipartite graphs with a dependency ordering on the edges, where weights capture the number of characters. Constraint solving plays a key role in our approach. Transforming a CSS file into a CSS-graph problem requires us to extract the dependency ordering on the edges (an NP-hard problem), which requires us to solve the selector intersection problem. To this end, we provide the first full formalisation of CSS3 selectors (the most stable version of CSS) and reduce their selector intersection problem to satisfiability of quantifier-free integer linear arithmetic, for which highly optimised SMT-solvers are available. To solve the above NP-hard graph optimisation problem, we show how Max-SAT solvers can be effectively employed. We have implemented our rule-merging algorithm and tested it against approximately 70 real-world examples (including examples from each of the top 20 most popular websites). We also used our benchmarks to compare our tool against six well-known minifiers (which implement other optimisations). Our experiments suggest that our tool produced larger savings. A substantially better minification rate was shown when our tool is used together with these minifiers.

中文翻译:

通过约束求解进行 CSS 缩小

缩小是一种被广泛接受的技术,旨在减少通过网络传输的代码的大小。本文关注级联样式表 (CSS) 的语义保留缩小问题——事实上用于样式化 Web 文档的语言——基于合并相似的规则。CSS 的级联特性使得 CSS 文件的语义对文件中规则的顺序很敏感。为了自动识别最能最小化文件大小的规则合并机会,我们将规则合并问题简化为关于“CSS-graphs”的问题,即在边缘上具有依赖排序的节点加权二分图,其中权重捕获数字的字符。约束求解在我们的方法中起着关键作用。将 CSS 文件转换为 CSS-graph 问题需要我们提取边上的依赖排序(一个 NP-hard 问题),这需要我们解决选择器交集问题。为此,我们提供了 CSS3 选择器(CSS 的最稳定版本)的第一个完整形式化,并将它们的选择器交叉问题减少到无量词整数线性算法的可满足性,为此可以使用高度优化的 SMT 求解器。为了解决上述 NP-hard 图优化问题,我们展示了如何有效地使用 Max-SAT 求解器。我们已经实现了我们的规则合并算法,并针对大约 70 个实际示例(包括来自前 20 个最受欢迎网站的示例)对其进行了测试。我们还使用我们的基准将我们的工具与六个著名的缩小器(它们实现了其他优化)进行了比较。我们的实验表明我们的工具产生了更大的节省。当我们的工具与这些缩小器一起使用时,显示出明显更好的缩小率。
更新日期:2019-06-19
down
wechat
bug