pas2js minifier

From Free Pascal wiki
Revision as of 17:33, 19 November 2018 by Mattias2 (talk | contribs) (Started tipps and tricks for reducing js code size)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Overview

This page explains ways to reduce and/or compress the pas2js generated JavaScript.

Omit unneeded code

  • Use pas2js option -Jc to generate one JavaScript program. This allows the compiler to use Whole Program Optimization (wpo) to determine all unused identifiers.
  • Use -O1 to omit unused identifiers. If a record/class is used, every unused member/method is omitted.
  • By default published properties/methods are kept and will generate type information (RTTI). If you don't need that you can ...
    • use {$modeswitch omitrtti} (since pas2js 1.1), which treats class section 'published' as 'public' and typeinfo() does not work on symbols declared with this switch.
    • use -OoRemoveNotUsedPublished to omit all published properties not referenced at compile time.

Third party minifier

There are several free minifiers for JavaScript. A minifier removes unneeded characters and replaces some code without changing its functionality.

As an example here is how to use uglifyjs with pas2js: