JSZap: compressing JavaScript code

  • Authors:
  • Martin Burtscher;Benjamin Livshits;Benjamin G. Zorn;Gaurav Sinha

  • Affiliations:
  • University of Texas at Austin;Microsoft Research;Microsoft Research;IIT Kanpur

  • Venue:
  • WebApps'10 Proceedings of the 2010 USENIX conference on Web application development
  • Year:
  • 2010

Quantified Score

Hi-index 0.00

Visualization

Abstract

JavaScript is widely used in web-based applications, and gigabytes of JavaScript code are transmitted over the Internet every day. Current efforts to compress JavaScript to reduce network delays and server bandwidth requirements rely on syntactic changes to the source code and content encoding using gzip. This paper considers reducing the JavaScript source to a compressed abstract syntax tree (AST) and transmitting it in this format. An AST-based representation has a number of benefits including reducing parsing time on the client, fast checking for well-formedness, and, as we show, compression. With JSZAP, we transform the JavaScript source into three streams: AST production rules, identifiers, and literals, each of which is compressed independently. While previous work has compressed Java programs using ASTs for network transmission, no prior work has applied and evaluated these techniques for JavaScript source code, despite the fact that it is by far the most commonly transmitted program representation. We show that in JavaScript the literals and identifiers constitute the majority of the total file size and we describe techniques that compress each stream effectively. On average, compared to gzip we reduce the production, identifier, and literal streams by 30%, 12%, and 4%, respectively. Overall, we reduce total file size by 10% compared to gzip while, at the same time, benefiting the client by moving some of the necessary processing to the server.