skip to main content
research-article
Free Access

CSS Minification via Constraint Solving

Published:19 June 2019Publication History
Skip Abstract Section

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.

References

  1. Alexa Internet. 2017. Alexa Top 500 Global Sites. Retrieved from https://www.alexa.com/topsites.Google ScholarGoogle Scholar
  2. 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 ScholarGoogle Scholar
  3. Josep Argelich, Chu Min Li, Felip Manyà, and Jordi Planes. 2016. Max-SAT’16 Competition. Retrieved from http://maxsat.ia.udl.cat/.Google ScholarGoogle Scholar
  4. Tab Atkins Jr., Elika J. Etemad, and Florian Rivoal. 2017. CSS Snapshot 2017. Retrieved from https://www.w3.org/TR/css-2017.Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. Johan Bleuzen. 2017. cssmin. Retrieved from https://www.npmjs.com/package/cssmin.Google ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarCross RefCross Ref
  10. Bert Bos. 2016. Cascading Style Sheets Level 2 Revision 2 (CSS 2.2) Specification. Retrieved from https://www.w3.org/TR/CSS22/.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. Aaron R. Bradley and Zohar Manna. 2007. The Calculus of Computation: Decision Procedures with Applications to Verification. Springer-Verlag New York, Secaucus, NJ. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ben Briggs et al. 2015. cssnano. Retrieved from http://cssnano.co.Google ScholarGoogle Scholar
  14. Hampton Catlin, Natalie Weizenbaum, Chris Eppstein et al. 2006. Sass. Retrieved from http://sass-lang.com/.Google ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. Steve Clay et al. 2017. minify. Retrieved from https://github.com/mrclay/minify.Google ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Roman Dvornov et al. 2017. csso. Retrieved from https://github.com/css/csso.Google ScholarGoogle Scholar
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. 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 ScholarGoogle Scholar
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle Scholar
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. Jake Hickenlooper. 2014. stripmq. Retrieved from https://www.npmjs.com/package/stripmq.Google ScholarGoogle Scholar
  32. 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 ScholarGoogle Scholar
  33. Jan Hidders. 2003. Satisfiability of XPath expressions. In Proceedings of the 9th International Workshop on Database Programming Languages (DBPL’03). 21--36.Google ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle Scholar
  37. Meitar Moscovitz and Joseph R. Lewis. 2010. AdvancED CSS. APress.Google ScholarGoogle Scholar
  38. 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 ScholarGoogle Scholar
  39. Leonid Libkin. 2006. Logics for unranked trees: An overview. Logic. Methods Comput. Sci. 2, 3 (2006).Google ScholarGoogle Scholar
  40. Leonid Libkin and Cristina Sirangelo. 2010. Reasoning about XML with temporal logics and automata. J. Appl. Logic 8, 2 (2010), 210--232.Google ScholarGoogle ScholarCross RefCross Ref
  41. Glacomo Martino et al. 2013. UnCSS. Retrieved from https://github.com/giakki/uncss.Google ScholarGoogle Scholar
  42. Maarten Marx. 2005. Conditional XPath. ACM Trans. Database Syst. 30, 4 (2005), 929--959. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Maarten Marx and Maarten de Rijke. 2005. Semantic characterizations of navigational XPath. SIGMOD Rec. 34, 2 (2005), 41--46. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  46. 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 ScholarGoogle Scholar
  47. A. Muscholl and I. Walukiewicz. 2005. An NP-complete fragment of LTL. Int. J. Found. Comput. Sci. 16, 4 (2005), 743--753.Google ScholarGoogle ScholarCross RefCross Ref
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. Frank Neven. 2002. Automata theory for XML researchers. SIGMOD Rec. 31, 3 (Sept. 2002), 39--46.Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle Scholar
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. Jakub Pawlowicz. 2017. Clean-css. Retrieved from https://github.com/jakubpawlowicz/clean-css.Google ScholarGoogle Scholar
  54. René Peeters. 2003. The maximum edge biclique problem is NP-complete. Discrete Appl. Math. 131, 3 (2003), 651--654. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Justyna Petke. 2015. Bridging Constraint Satisfaction and Boolean Satisfiability. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Armin Rigo et al. 2007. PyPy. Retrieved from http://pypy.org/.Google ScholarGoogle Scholar
  57. B. Scarpellini. 1984. Complexity of subcases of presburger arithmetic. Trans. AMS 284, 1 (1984), 203--218.Google ScholarGoogle ScholarCross RefCross Ref
  58. 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 ScholarGoogle Scholar
  59. 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 ScholarGoogle ScholarCross RefCross Ref
  60. Alexis Sellier et al. 2009. Less. Retrieved from http://lesscss.org/.Google ScholarGoogle Scholar
  61. Thomas Sha et al. 2014. YUI Compressor. Retrieved from http://yui.github.io/yuicompressor/.Google ScholarGoogle Scholar
  62. Slant. 2017. Eight Best CSS Minifiers as of 2017. Retrieved from https://www.slant.co/topics/261/ best-css-minifiers.Google ScholarGoogle Scholar
  63. 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 ScholarGoogle Scholar
  64. Steve Souders. 2007. High Performance Web Sites: Essential Knowledge for Front-End Engineers. O’Reilly Media.Google ScholarGoogle Scholar
  65. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  66. Friedrich Steimann. 2018. Constraint-based refactoring. ACM Trans. Program. Lang. Syst. 40, 1 (2018), 2:1--2:40. Google ScholarGoogle ScholarDigital LibraryDigital Library
  67. 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 ScholarGoogle Scholar
  68. Balder ten Cate, Tadeusz Litak, and Maarten Marx. 2010. Complete axiomatizations for XPath fragments. J. Appl. Logic 8, 2 (2010), 153--172.Google ScholarGoogle ScholarCross RefCross Ref
  69. Balder ten Cate and Maarten Marx. 2007. Navigational XPath: Calculus and algebra. SIGMOD Rec. 36, 2 (2007), 19--26. Google ScholarGoogle ScholarDigital LibraryDigital Library
  70. Balder ten Cate and Maarten Marx. 2009. Axiomatizing the logical core of XPath 2.0. Theory Comput. Syst. 44, 4 (2009), 561--589. Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  72. Unicode, Inc. 2016. The Unicode Standard, Version 9.0. Retrieved from http://www.unicode.org/versions/Unicode9.0.0.Google ScholarGoogle Scholar
  73. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  74. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. CSS Minification via Constraint Solving

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM Transactions on Programming Languages and Systems
              ACM Transactions on Programming Languages and Systems  Volume 41, Issue 2
              Special Issue on ESOP 2017 and Regular Papers
              June 2019
              305 pages
              ISSN:0164-0925
              EISSN:1558-4593
              DOI:10.1145/3320016
              Issue’s Table of Contents

              Copyright © 2019 ACM

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 19 June 2019
              • Accepted: 1 November 2018
              • Revised: 1 October 2018
              • Received: 1 September 2017
              Published in toplas Volume 41, Issue 2

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • research-article
              • Research
              • Refereed

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader

            HTML Format

            View this article in HTML Format .

            View HTML Format
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!