Abstract
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.
- Alexa Internet. 2017. Alexa Top 500 Global Sites. Retrieved from https://www.alexa.com/topsites.Google Scholar
- E. Andreasen and A. Møller. 2014. Determinacy in static analysis for jQuery. In Proceedings of the Conference on Object-oriented Programming, Systems, Languages, and Applications (OOPSLA’14). 17--31.Google Scholar
- Josep Argelich, Chu Min Li, Felip Manyà, and Jordi Planes. 2016. Max-SAT’16 Competition. Retrieved from http://maxsat.ia.udl.cat/.Google Scholar
- Tab Atkins Jr., Elika J. Etemad, and Florian Rivoal. 2017. CSS Snapshot 2017. Retrieved from https://www.w3.org/TR/css-2017.Google Scholar
- Michael Benedikt, Wenfei Fan, and Floris Geerts. 2005. XPath satisfiability in the presence of DTDs. In Proceedings of the 24th ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems. 25--36.Google Scholar
Digital Library
- Michael Benedikt, Wenfei Fan, and Gabriel M. Kuper. 2003. Structural properties of XPath fragments. In Proceedings of the 9th International Conference on Database Theory (ICDT’03). 79--95.Google Scholar
- Nikolaj Bjørner and Nina Narodytska. 2015. Maximum satisfiability using cores and correction sets. In Proceedings of the 24th International Joint Conference on Artificial Intelligence (IJCAI’15). 246--252. Retrieved from http://ijcai.org/Abstract/15/041.Google Scholar
Digital Library
- Johan Bleuzen. 2017. cssmin. Retrieved from https://www.npmjs.com/package/cssmin.Google Scholar
- Mikołaj Bojańczyk. 2010. Automata for data words and data trees. In Proceedings of the 21st International Conference on Rewriting Techniques and Applications (RTA’10). 1--4.Google Scholar
Cross Ref
- Bert Bos. 2016. Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification. Retrieved from https://www.w3.org/TR/CSS22/.Google Scholar
- Martí Bosch, Pierre Genevès, and Nabil Layaïda. 2015. Reasoning with style. In Proceedings of the 24th International Joint Conference on Artificial Intelligence (IJCAI’15). 2227--2233. http://ijcai.org/Abstract/15/315. Google Scholar
Digital Library
- Aaron R. Bradley and Zohar Manna. 2007. The Calculus of Computation: Decision Procedures with Applications to Verification. Springer-Verlag New York, Secaucus, NJ. Google Scholar
Digital Library
- Ben Briggs et al. 2015. cssnano. Retrieved from http://cssnano.co.Google Scholar
- Hampton Catlin, Natalie Weizenbaum, Chris Eppstein et al. 2006. Sass. Retrieved from http://sass-lang.com/.Google Scholar
- T. Çelik, E. J. Etemad, D. Glazman, I. Hickson, P. Linss, and J. Williams. 2011. Selectors Level 3: W3C Recommendation 29 September 2011. Retrieved from http://www.w3.org/TR/2011/REC-css3-selectors-20110929/.Google Scholar
- Steve Clay et al. 2017. minify. Retrieved from https://github.com/mrclay/minify.Google Scholar
- Claire David, Leonid Libkin, and Tony Tan. 2012. Efficient reasoning about data trees via integer linear programming. ACM Trans. Database Syst. 37, 3 (2012), 19:1--19:28. Google Scholar
Digital Library
- L. Mendonça de Moura and N. Bjørner. 2008. Z3: An efficient SMT solver. In Proceedings of the International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS’08).Google Scholar
Digital Library
- Roman Dvornov et al. 2017. csso. Retrieved from https://github.com/css/csso.Google Scholar
- Elika J. Etemad and Tab Atkins Jr. 2013. Selectors Level 4: W3C Working Draft 2 May 2013. Retrieved from http://www.w3.org/TR/2013/WD-selectors4-20130502/.Google Scholar
- Diego Figueira. 2010. Reasoning on Words and Trees with Data: On Decidable Automata on Data Words and Data Trees in Relation to Satisfiability of LTL and XPath. Ph.D. Dissertation. Ecole Normale Superieure de Cachan.Google Scholar
- Ferenc Gécseg and Magnus Steinby. 1997. Handbook of formal languages, Vol. 3. Springer-Verlag New York, NY, Chapter Tree Languages, 1--68. Retrieved from http://dl.acm.org/citation.cfm?id=267871.267872.Google Scholar
- Floris Geerts and Wenfei Fan. 2005. Satisfiability of XPath queries with sibling axes. In Proceedings of the 10th International Symposium on Database Programming Languages (DBPL’05). 122--137.Google Scholar
Digital Library
- Pierre Genevès and Nabil Layaïda. 2006. A system for the static analysis of XPath. ACM Trans. Inf. Syst. 24, 4 (2006), 475--502. Google Scholar
Digital Library
- Pierre Genevès, Nabil Layaïda, and Vincent Quint. 2012. On the analysis of cascading style sheets. In Proceedings of the 21st World Wide Web Conference (WWW’12). 809--818.Google Scholar
Digital Library
- Pierre Genevès, Nabil Layaïda, Alan Schmitt, and Nils Gesbert. 2015. Efficiently deciding -calculus with converse over finite trees. ACM Trans. Comput. Log. 16, 2 (2015), 16:1--16:41. Google Scholar
Digital Library
- Georg Gottlob and Christoph Koch. 2002. Monadic queries over tree-structured data. In Proceedings of the 17th IEEE Symposium on Logic in Computer Science (LICS’02). 189--202. Google Scholar
Digital Library
- Matthew Hague and Anthony Widjaja Lin. 2017. MaxSAT benchmarks: CSS refactoring. In MaxSAT Evaluation 2017: Solver and Benchmark Descriptions, vol. B-2017-2. Department of Computer Science Series of Publications B, University of Helsinki.Google Scholar
- Matthew Hague, Anthony Widjaja Lin, and Chih-Duo Hong. 2018. Data and Source Code for Sat CSS. Retrieved from https://figshare.com/articles/Data_and_Source_Code_for_Sat_CSS/7277324.Google Scholar
- Matthew Hague, Anthony Widjaja Lin, and C.-H. Luke Ong. 2015. Detecting redundant CSS rules in HTML5 applications: A tree rewriting approach. In Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’15). 1--19.Google Scholar
Digital Library
- Jake Hickenlooper. 2014. stripmq. Retrieved from https://www.npmjs.com/package/stripmq.Google Scholar
- Ian Hickson, Robin Berjon, Steve Faulkner, Travis Leithead, Erika Doyle Navara, Edward O’Connor, and Silvia Pfeiffer. 2014. HTML5. Retrieved from https://www.w3.org/TR/html5/.Google Scholar
- Jan Hidders. 2003. Satisfiability of XPath expressions. In Proceedings of the 9th International Workshop on Database Programming Languages (DBPL’03). 21--36.Google Scholar
- Thibaud Hottelier and Rastislav Bodik. 2015. Synthesis of layout engines from relational constraints. In Proceedings of the ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’15). ACM, New York, NY, 74--88.Google Scholar
Digital Library
- S. H. Jensen, M. Madsen, and A. Møller. 2011. Modeling the HTML DOM and browser API in static analysis of JavaScript web applications. In Proceedings of the Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering (SIGSOFT/FSE’11). 59--69. Google Scholar
Digital Library
- S. H. Jensen, A. Møller, and P. Thiemann. 2009. Type analysis for JavaScript. In Proceedings of the International Static Analysis Symposium (SAS’09). 238--255.Google Scholar
- Meitar Moscovitz and Joseph R. Lewis. 2010. AdvancED CSS. APress.Google Scholar
- Enver Kayaaslan. 2010. On enumerating all maximal bicliques of bipartite graphs. In Proceedings of the 9th Cologne-Twente Workshop on Graphs and Combinatorial Optimization. 105--108.Google Scholar
- Leonid Libkin. 2006. Logics for unranked trees: An overview. Logic. Methods Comput. Sci. 2, 3 (2006).Google Scholar
- Leonid Libkin and Cristina Sirangelo. 2010. Reasoning about XML with temporal logics and automata. J. Appl. Logic 8, 2 (2010), 210--232.Google Scholar
Cross Ref
- Glacomo Martino et al. 2013. UnCSS. Retrieved from https://github.com/giakki/uncss.Google Scholar
- Maarten Marx. 2005. Conditional XPath. ACM Trans. Database Syst. 30, 4 (2005), 929--959. Google Scholar
Digital Library
- Maarten Marx and Maarten de Rijke. 2005. Semantic characterizations of navigational XPath. SIGMOD Rec. 34, 2 (2005), 41--46. Google Scholar
Digital Library
- Davood Mazinanian, Nikolaos Tsantalis, and Ali Mesbah. 2014. Discovering refactoring opportunities in cascading style sheets. In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering, (FSE’14). 496--506.Google Scholar
Digital Library
- Ali Mesbah and Shabnam Mirshokraie. 2012. Automated analysis of CSS rules to support style maintenance. In Proceedings of the 34th International Conference on Software Engineering (ICSE’12). 408--418.Google Scholar
Digital Library
- Leo A. Meyerovich and Rastislav Bodík. 2010. Fast and parallel webpage layout. In Proceedings of the 19th International Conference on World Wide Web (WWW’10). 711--720.Google Scholar
- A. Muscholl and I. Walukiewicz. 2005. An NP-complete fragment of LTL. Int. J. Found. Comput. Sci. 16, 4 (2005), 743--753.Google Scholar
Cross Ref
- Nina Narodytska and Fahiem Bacchus. 2014. Maximum satisfiability using core-guided MaxSAT resolution. In Proceedings of the 28th AAAI Conference on Artificial Intelligence. 2717--2723. Retrieved from http://www.aaai.org/ocs/index.php/AAAI/AAAI14/paper/view/8513. Google Scholar
Digital Library
- Frank Neven. 2002. Automata theory for XML researchers. SIGMOD Rec. 31, 3 (Sept. 2002), 39--46.Google Scholar
Digital Library
- Frank Neven and Thomas Schwentick. 2006. On the complexity of XPath containment in the presence of disjunction, DTDs, and variables. Logic. Methods Comput. Sci. 2, 3 (2006).Google Scholar
- Pavel Panchekha, Adam T. Geller, Michael D. Ernst, Zachary Tatlock, and Shoaib Kamil. 2018. Verifying that web pages have accessible layout. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’18). 1--14. Google Scholar
Digital Library
- Pavel Panchekha and Emina Torlak. 2016. Automated reasoning for web page layout. In Proceedings of the ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’16). 181--194.Google Scholar
Digital Library
- Jakub Pawlowicz. 2017. Clean-css. Retrieved from https://github.com/jakubpawlowicz/clean-css.Google Scholar
- René Peeters. 2003. The maximum edge biclique problem is NP-complete. Discrete Appl. Math. 131, 3 (2003), 651--654. Google Scholar
Digital Library
- Justyna Petke. 2015. Bridging Constraint Satisfaction and Boolean Satisfiability. Springer. Google Scholar
Digital Library
- Armin Rigo et al. 2007. PyPy. Retrieved from http://pypy.org/.Google Scholar
- B. Scarpellini. 1984. Complexity of subcases of presburger arithmetic. Trans. AMS 284, 1 (1984), 203--218.Google Scholar
Cross Ref
- M. Schäfer, M. Sridharan, J. Dolby, and F. Tip. 2013. Dynamic determinacy analysis. In Proceedings of the Annual ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’13). 165--174.Google Scholar
- Helmut Seidl, Thomas Schwentick, Anca Muscholl, and Peter Habermehl. 2004. Counting in trees for free. In Proceedings of the 31st International Colloquium on Automata, Languages and Programming (ICALP’04). 1136--1149.Google Scholar
Cross Ref
- Alexis Sellier et al. 2009. Less. Retrieved from http://lesscss.org/.Google Scholar
- Thomas Sha et al. 2014. YUI Compressor. Retrieved from http://yui.github.io/yuicompressor/.Google Scholar
- Slant. 2017. Eight Best CSS Minifiers as of 2017. Retrieved from https://www.slant.co/topics/261/ best-css-minifiers.Google Scholar
- Jennifer Slegg. 2017. Google mobile first index: Page speed included as a ranking factor. Retrieved from http://www.thesempost.com/google-mobile-first-index-page-speed-ranking/.Google Scholar
- Steve Souders. 2007. High Performance Web Sites: Essential Knowledge for Front-End Engineers. O’Reilly Media.Google Scholar
- M. Sridharan, J. Dolby, S. Chandra, M. Schäfer, and F. Tip. 2012. Correlation tracking for points-to analysis of JavaScript. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP’12). 435--458. Google Scholar
Digital Library
- Friedrich Steimann. 2018. Constraint-based refactoring. ACM Trans. Program. Lang. Syst. 40, 1 (2018), 2:1--2:40. Google Scholar
Digital Library
- Larry J. Stockmeyer and Albert R. Meyer. 1973. Word problems requiring exponential time: Preliminary report. In Proceedings of the 5th Annual ACM Symposium on Theory of Computing. 1--9.Google Scholar
- Balder ten Cate, Tadeusz Litak, and Maarten Marx. 2010. Complete axiomatizations for XPath fragments. J. Appl. Logic 8, 2 (2010), 153--172.Google Scholar
Cross Ref
- Balder ten Cate and Maarten Marx. 2007. Navigational XPath: Calculus and algebra. SIGMOD Rec. 36, 2 (2007), 19--26. Google Scholar
Digital Library
- Balder ten Cate and Maarten Marx. 2009. Axiomatizing the logical core of XPath 2.0. Theory Comput. Syst. 44, 4 (2009), 561--589. Google Scholar
Digital Library
- Frank Tip, Robert M. Fuhrer, Adam Kiezun, Michael D. Ernst, Ittai Balaban, and Bjorn De Sutter. 2011. Refactoring using type constraints. ACM Trans. Program. Lang. Syst. 33, 3 (2011), 9:1--9:47. Google Scholar
Digital Library
- Unicode, Inc. 2016. The Unicode Standard, Version 9.0. Retrieved from http://www.unicode.org/versions/Unicode9.0.0.Google Scholar
- Moshe Y. Vardi. 1995. An automata-theoretic approach to linear temporal logic. In Proceedings of the 8th Banff Higher-order Workshop on Logics for Concurrency—Structure versus Automata. 238--266. Google Scholar
Digital Library
- Mihalis Yannakakis. 1978. Node- and edge-deletion NP-complete problems. In Proceedings of the 10th Annual ACM Symposium on Theory of Computing. 253--264. Google Scholar
Digital Library
Index Terms
CSS Minification via Constraint Solving






Comments