Microsoft Ajax Minifier
Ajax MinifierはMSNチームのRon Logon氏が作成したツールです。Microsoft Ajax Minifierを使用すると、カスケーディングスタイルシートファイル(.css)およびJavaScriptファイル(.js)のサイズを縮小することによってWebアプリケーションのパフォーマンスを向上させることができます。Ajax Minifierは次のような処理を実施してファイルのサイズを小さくします。
- コメントの削除
- 不要な空白の削除
- 不要なセミコロンの削除
- 参照されていない関数の削除
- 不要な括弧の削除
- ローカル変数と関数の名前の短縮
- 文字列のシングルクォーテーションとダブルクォーテーションの調整
- 隣接した変数宣言のとりまとめ
- 実行されないコードの削除
- など
Ajax Minifierには、プログラムからAPIを呼び出すことによって利用できるdll版と単体で利用できるexeファイルを含むmsiインストーラー版がありました。
dll版は、現在(2019年1月)でも、nugetでAjaxMinとして取得できます。
exeファイルを含むmsiインストーラー版は、CodePlexでAjaxMinプロジェクトとして公開されていました。しかし、CodePlexが
CodePlex was Microsoft's free, open source project hosting site, which ran from 2006 through 2017. (日本語訳) CodePlexはマイクロソフトの無料のオープンソースプロジェクトホスティングサイトで、2006年から2017年まで運営されていました。
とあるように、2017年で終了してしまいました。今はアーカイブとしてデータをダウンローできるだけとなってしまいました。
インストーラー等が取得できないのは不便なので、ここに各種情報を日本語で記録として残し、また、最終版をダウンロードできるようにします。
ダウンロードはこちら(バージョン5.14)です。
このサイトからダウンロードできるようにしますが、モジュールの権利などはすべて元の製作者であるRon Logon氏にあります。
ここより下は、各種情報を参照できる記録として残すために、当時の情報をそのまま日本語に翻訳しています。(変更履歴は翻訳していません)
プロジェクト自体は、2015年1月を最後に活動が止まっています。そのため、現在ではバグ報告やフィードバック等はできません。内容は参考程度にとどめてください。
プロジェクトの概要
Microsoft Ajax Minifierを使用すると、カスケーディングスタイルシートファイル(.css)およびJavaScriptファイル(.js)のサイズを縮小することによってWebアプリケーションのパフォーマンスを向上させることができます。
JSファイルとCSSファイルの両方を縮小し、さらにオプションを使用することでJavaScriptファイル用のソースマップを作成します。
コマンドラインで-analyze
オプションを使用して、lint形式の構文チェックとコードの変数分析を実行します。
コマンドラインで-pretty
オプションを使用すると、見やすく読みやすい複数行形式で出力できます(縮小前の縮小コードに適しています)。
Ajax Minifierで縮小されたJavaScriptおよびCSSファイルはそのまま機能するはずです。良い結果を得るためにコードに特別なことをする必要はありません。縮小してもファイルが機能しない場合は、最初にJavaScriptコードにeval
ステートメントが含まれているかどうかを確認してください。それでも問題が解決しない場合は、Ajax Minifierを修正するために、問題のページにレポートを提出してください。
新機能のご要望がございましたら、「問題」ページでお気軽にお問い合わせください。機能要求がそれをコードにすることを保証することはできません。
公式NuGetパッケージ (Offical NuGet Package)
C#プロジェクトをそのように管理したい場合は、DLL版のMicrosoft Ajax Minifier用の公式NuGetパッケージがあります。
http://nuget.org/packages/AjaxMin
AjaxMinはRon Logan氏によって作成されました。
貢献 (Contributing)
このプロジェクトは貢献と提案を歓迎します。ほとんどの寄付は、あなたが寄付を使用する権利を私達に与える権利を有し、実際にそうする権利を有すると宣言する寄付者使用許諾契約(CLA)に同意することをあなたに要求します。詳細については、https://cla.microsoft.comをご覧ください。
プルリクエストを送信すると、CLAボットが自動的にCLAを提供してPRを適切に装飾する必要があるかどうかを判断します(ラベル、コメントなど)。ボットの指示に従ってください。あなたは私たちのCLAを使ってすべてのリポジトリで一度だけこれをする必要があるでしょう。
このプロジェクトはマイクロソフトオープンソース行動規範を採用しています。詳細については、行動規範のFAQを参照するか、opencode@microsoft.comに追加の質問やコメントをお寄せください。
変更履歴
2015-01-28 Microsoft Ajax Minifier 5.14
- Issue #21611 – add
"noswap"
option to CSS -colors switch so that names don’t get swapped with shorter hex values, or hex with shorter name values. make the default -colors switch value be HEX, not STRICT. - Fix for issue #21680 – regular expression literal parsing error
2014-12-16 Microsoft Ajax Minifier 5.13
- fix issue #21609 – escaped closing bracket inside regular expression literal set not being escaped.
- fix issue #21549 – comma-separated lists in progid values must have trailing whitespace.
- fix issue #21162 – bad OP= optimization.
- Add XDomainRequest and DocumentTouch as known globals.
- Add debug timing for CSS (though not as detailed as JS debug timing).
- Perf: add a string builder pool so we aren’t creating/destroying string builders all the time.
2014-11-19 Microsoft Ajax Minifier 5.12
- Fix for issue #21164 – variable renaming issue when -evals:immediate switch is used.
- Fix for issue #21292 – null-reference exception when using the scriptsharp source map generator.
- Fix for issue #21494 – sourceMappingUrl comment not added when using the Minifier object.
- remove empty CSS rules or @media directives when their blocks are empty.
- add some more known global names
- minor performance improvements.
2014-07-01 Microsoft Ajax Minifier 5.11
- Fix for issue #21057 – don’t strip spaces before CSS !important token.
- Fix for issue #20912 – support for CSS :any and :matches pseudoclasses.
2014-05-27 Microsoft Ajax Minifier 5.10
- Fix for Issue #20875 – echo switch doesn’t work for CSS
- CSS should honor the SASS source-file comments
- JS should allow multi-line comment directives
2014-04-26 Microsoft AjaxMinifier 5.9
Just a couple minor features I needed for work:
- new -amd switch that automatically adds
"define"
and"require"
to the known globals list, and removes duplicate named modules{{define("modulename",...)}}
from the combined source file. - stand-alone tokens or tokens that are the only contents of a string literal will be examined, and if they start with CurrentCulture, the dotted path will be resolved against the thread’s CultureInfo.CurrentCulture object and replace the token.
For example:
{{ var monthNames = %CurrentCulture.DateTimeFormat.MonthNames%; var percent = "%CurrentCulture.NumberFormat.PercentSymbol%"; }}
: will result in:
{{ var monthNames=["January","February",...],percent="%" }}
: and the actual values will vary by the thread’s current culture. If the culture isn’t getting set elsewhere, you can set the thread’s current culture with the -culture:LL-CC switch. This switch, however, will set the thread’s current culture and not reset it back to what it was, so beware of any unintended side-effects.
2014-02-28 Microsoft Ajax Minifier 5.8
- Issue #20705 – add support for SharePoint Theming comments in CSS.
- Issue #20719 – manifest processing was ignoring
<resource>
elements. - Issue #20739 – in an expression-level call to JSParser.Parse, do not convert commas to semicolons because they aren’t statements, but actual subexpressions.
2014-01-11 Microsoft Ajax Minifier 5.7
- Add support for “typed array” constructors.
- Fix for issue #20611 – Chrome implemented a proposed errata for Media Queries that requires whitespace before the “and” conjunction. Make sure the CSS minifier doesn’t strip it out.
2013-12-18 Microsoft Ajax Minifier 5.6
- Fix for bug 20541 – in CSS strings, and ASCII-9 is not a
"\t"
, ASCII-10 is not"\n"
, ASCII-13 is not"\r"
, and ASCII-12 is not"\f"
. - Fix bug 20517 – in CSS, invalid color hash values were parsed incorrectly and caused a slew of other irrelevant errors. Just log the invalid hash color and continue on.
- Make the
<input>
and<output>
elements in manifest files accept the legacy"enc"
attribute name in addition to the newer"encoding"
attribute. Changed the online documentation to reflect the new name. - throw invalid-switch errors when switches incompatible with
-pretty
are used together. (NOTE: the -pretty switch is a special switch that does not change the input other than to add whitespace to make it more readable, so any switches that cause the input to be modified cannot be used with it. Please use the -line switch to make modified code output on multiple lines.) - added the ability to use -pretty with JSON input, so you can use it to make JSON output returned from services a little easier to debug.
2013-12-09 Microsoft Ajax Minifier 5.5
- Fix bug #20499, where the Append method was marked as internal. Also, the Manifest build task was always showing all errors and warnings; changed it to respect any -warn:N arguments in the manifest settings to be able to crank down the severity threshold.
2013-12-03 Microsoft Ajax Minifier 5.4
- Fix potential infinite loop problem introduced in 5.3. Add option to pretty-print JSON data.
2013-11-16 Microsoft Ajax Minifier 5.3
- Switch back to new SourceMap v3 syntax of
//#
for the comment, not//@
- more pre-defined globals
- fix issue #20273
- fix issue #20298
- fix issue #20417
- fix issue #20420
2013-09-30 Microsoft Ajax Minifier 5.2
Mostly internal code tweaks.
- added -nosize switch to turn off the size- and gzip-calculations done after minification.
- removed the comments in the build targets script for the old AjaxMin build task (discussion #458831).
- Fixed an issue with extended Unicode characters encoded inside a string literal with adjacent
\uHHHH\uHHHH
sequences. - Fixed an IndexOutOfRange exception when encountering a CSS identifier that’s a single underscore character (_).
In previous builds, the net35 and net20 folders created by the MSI were just copying the .NET 4.0 DLLs due to a build script copy/paste error. That should be resolved; apologies to anyone encountering issues with using AjaxMin with older .NET frameworks.
REMINDER: the 5.x release includes breaking changes from 4.x. See Migrating from v4 to v5 for more information.
2013-09-16 Microsoft Ajax Minifier 5.1
- Reverted all the DLLs’ “Platform Target” project settings to “Any CPU.” The problem with putting them to “x86” is that a host application built to “Any CPU” or “x64” fails to load the DLL. So the EXEs will remain “x86”; only the DLLs are reverted to “Any CPU”. This should fix Issue #20199.
REMINDER: the 5.x release includes breaking changes from 4.x. See Migrating from v4 to v5 for more information.
2013-09-16 Microsoft Ajax Minifier 5.0
! New major version release with breaking changes!
If you are using AjaxMin on the command-line, or via the library’s Microsoft.Ajax.Utilities.Minifier object’s MinifyJavaScript or MinifyStyleSheet methods, or via the provided build tasks, no breaking changes should be present.
If you are creating and using JSParser objects directly, creating and using classes derived from IVisitor, and/or defining your own custom AST node classes, you will need to perform some migration work. See Migrating from v4 to v5 for more information.
!! Support for some EcmaScript 6 syntax.
Please see EcmaScript 6 Supported Syntax for more information.
!! Bug Fixes:
- fix for Issue #20189 – build task doesn’t build when source and destination are the same file.
2013-07-12 Microsoft Ajax Minifier 4.96
- Fix for issue #19957: EXE should output the name of the file(s) being minified.
- Discussion #449181: throw a Sev-2 warning when trailing commas are detected on an Array literal. Perfectly legal to do so, but the behavior ends up working differently on different browsers, so throw a cross-browser warning.
- Add a few more known global names for improved ES6 compatibility
- update Nuget package to version 2.5 and automatically add the AjaxMin.targets to your project when you update the package. This target will automatically build any files in your project with the extension .AjaxMin using the AjaxMinManifestTask.
- get rid of multiple code paths and the maintenance nightmare of maintaining them separately for normal, echo, and preprocess-only. The preprocess-only path wasn’t even parsing the input files.
- if the length property is being applied to a string literal which has a known length, replace the property access with the actual length.
- remove most custom exceptions, and remove the serialization code from the remaining one. Needed for WebGrease and its partially-trusted callers scenarios.
2013-06-25 Microsoft Ajax Minifier 4.95
- update parser to allow for CSS3 calc( function to nest.
- add recognition of -pponly (Preprocess-Only) switch in AjaxMinManifestTask build task.
- Fix crashing bug in EXE when processing a manifest file using the -xml switch and an error message needs to be displayed (like a missing input file).
- Create separate Clean and Bundle build tasks for working with manifest files (AjaxMinManifestCleanTask and AjaxMinBundleTask). Removed the IsCleanOperation from AjaxMinManifestTask — use AjaxMinManifestCleanTask instead. Updated the provided .targets file as such.
- Add ability for CSS parser to recognize CSS-style multi-line #SOURCE comments, since single-line comments aren’t actually valid CSS syntax. Needed because the new bundling task needs to output valid CSS, since the results are exposed and not immediately consumed by the tool.
2013-06-17 Microsoft Ajax Minifier 4.94
- add dstLine and dstCol attributes to the
-Analyze
output in XML mode. - un-combine leftover comma-separates expression statements after optimizations are complete so downstream tools don’t stack-overflow on really deep comma trees.
- add support for using a single source map generator instance with multiple runs of MinifyJavaScript, assuming that the results are concatenated to the same output file.
2013-06-03 Microsoft Ajax Minifier 4.93
- Added
-esc[:BOOL]
switch (CodeSettings.AlwaysEscapeNonAscii property) to always force non-ASCII character (ch > 0x7f) to be escaped as the JavaScript\uXXXX
sequence. This switch should be used if creating a Symbol Map and outputting the result to the a text encoding other than UTF-8 or UTF-16 (ASCII, for instance). - Fixed a bug where a complex comma operation is the operand of a return statement, and it was looking at the wrong variable for possible optimization of += to just +.
2013-05-28 Microsoft Ajax Minifier 4.92
- Fixed issues around certain numeric literals that have member-operators applied to them.
- InputFolder was being ignored by ManifestTask, leading to incorrect “missing input file” errors.
2013-05-07 Microsoft Ajax Minifier 4.91
- Add optional
"origin"
property to manifest<input>
elements. Settingorigin="external"
on an input file makes the build process ignore all warnings for the given file. - Add the .NET 3.5 DLLs (AjaxMin.dll and AjaxMinTask.dll) to the NuGet package tools\net35 folder.
- Add a “clean” step for the AjaxMinManifestTask so that output files specified in the manifest can be deleted in the build’s clean process.
2013-04-26 Microsoft Ajax Minifier 4.90
- Fix for Issue #19632 – when generating source maps, need to wrap the //@ sourceMappingURL=url comment inside a multiline comment to keep IE from thinking it’s a conditional-compilation comment and throwing an error.
- Fix for Issue #19639 – when using the -minify:no switch, don’t optimize out empty blocks, and especially not empty else-clauses. The switch means don’t modify the DOM, so DOM modifications should not be performed.
2013-04-23 Microsoft Ajax Minifier 4.89
- Fix for second follow-up issue discovered in Issue #19459. Inner scopes known at compile time that reference a field in an outer scope that isn’t known need to add that field to the avoid-names list before renaming their local variables, because we can’t rename that outer variable (because it’s in an unknown scope), and we don’t want to accidentally reuse the name. Only an issue when the -evals:safeall switch is used, especially when minifying already-minified files.
2013-04-19 Microsoft Ajax Minifier 4.88
- Fix for issue #19459 for the BUILD TASKS. When concatenating source files, append blank lines and semicolons as appropriate to make sure files are terminated properly.
2013-04-12 Microsoft Ajax Minifier 4.87
- Fix for issue #19459 – need to insert semicolons between concatenated files if they don’t already end with a semicolon.
Potential Breaking Change
To concatenate partial script files without getting semicolons added between them, add a single-line comment at the end of your partial script files, ending with a semicolon: //; The code is simply doing a text-comparison for the trailing semicolon (ignoring terminating whitespace), so this will be enough to signal AjaxMin to not add the semicolon and break the assembled partial code files. - Fix for issue #19559 – don’t replace single-reference object literal variable declarations when the reference is within an iteration statement.
- Somehow the “unreferenced variable” warnings were previously accidentally disabled and I didn’t notice; reinstating those warnings.
2013-03-29 Microsoft Ajax Minifier 4.86
- Fix file concatenation issues
2013-03-21 Microsoft Ajax Minifier 4.85
JavaScript:
- Don’t lose important comments at the end of block or functions (issue #19416).
- fix bad optimization of Array shift calls that are the only reference to a variable initialized with an array literal (issue #19440).
- created separate EmptyStatement node instead of using an empty block.
- ignore important comments that would otherwise interfere with the normal parsing of the source code.
CSS:
- don’t strip off units for zero-value Angles, Times, Frequencies, or Resolutions.
2013-02-11 Microsoft Ajax Minifier 4.84
- Fixed a bug whereby passing a null or empty string to the CssParser. Parse(string) method would throw an exception. The command-line or task paths for executing the code were not affected by the bug.
2013-02-06 Microsoft Ajax Minifier 4.83
- Fixed issue #19309 – regexp literals with the “g” global flag cannot be treated as constants as they contain state that is used in subsequent exec() calls. Don’t move them from a variable to an in-place literal.
- Fixed issue #19296 – ///#DEBUG blocks were getting removed unless the DEBUG preprocessor define existed, and totally ignored the StripDebugStatements CodeSettings flag. Legacy builds switched off that property, so people broke when upgrading. Changed the logic to leave those comments in if either the DEBUG preprocessor define exists OR the StripDebugStatements flag is false. Default is still to remove.
- Fixed issue where throw statements could possibly line-break between the throw keyword and its operand (not allowed in JS syntax) when the -line:N switch is used to break lines after they have crossed the N-character threshold.
- comments containing
"@preserve"
or"@license"
should be treated as important comments and not removed. This is an alternative way to create important comments, {“beyond the current /*! … */ and //! … formats”}.
2013-02-05 Microsoft Ajax Minifier 4.82
Fixing a bug around invalid JS (for the current ES5 specs): function declarations at other than source-element scopes. Technically it’s invalid to put a function declaration within, say, an if-block; but browsers allow it — unfortunately they treat them differently since it’s not a spec’d scenario. Some declare the name immediately as if it were at the source element level; some don’t declare the name until the declaration is “executed.” The difference could lead to hard-to-debug cross-browser issues.
AjaxMin was updated a while back to support the upcoming ES6 spec, which calls for block-level scoping of lexical elements, including function declarations. So it will be perfectly valid to declare a function within an if-statement — but the declaration will only be scoped to that block and not visible outside it. The end result is that if someone writes some JavaScript to the current browsers thinking their function declaration will be scoped to the variable scope, AjaxMin will break that code upon minification by renaming it to something that doesn’t collide within the lexical scope — but might collide in the variable scope, clobbering values.
Updated AjaxMin such that it maintains a linkage to the variable scope so the lexical function declaration won’t collide with another variable-scope field during renaming. Also added a low-sev warning about the situation, since most people aren’t coding ES6 yet anyway. Will have to revisit later; maybe add a JS version switch for ES5 vs ES6.
2013-01-21 Microsoft Ajax Minifier 4.81
- Fixed issue where the AjaxMin build task was ignoring any
-enc
switches applied to the task and only outputting as UTF-8 with no BOM.
2013-01-15 Microsoft Ajax Minifier 4.80
- Fix for issue #19190 in the AjaxManifestTask build task: the manifest file itself should be treated as an input file and modification to it should cause output to be regenerated during build.
2013-01-14 Microsoft Ajax Minifier 4.79
- NEW SETUP PROJECT.
- If for some reason the MSI doesn’t work for you, please let me know immediately. I had to create a new WiX setup project as part of the VS2012 migration. It should work just fine, but I get nervous any time I touch the MSI itself.
- Fix for Issue #19055 – Manifest XML file didn’t accept .RESX resources, just .RESOURCES.
- Fix for issue 19087 – used to throw an error if it encountered a CSS3 @charset rule anywhere other than the exact first character in the file. Now it’s a little more forgiving if the first few characters are BOM characters. Also, it will now continue to process the input properly, and throw a lesser-severity error that is more descriptive of what is actually going on (@charset not at start of file).
- Fix a crashing issue when the input JS ended in an empty and unterminated string delimiter.
- Fixed the context of the returned overall parsed script block; the end point was incorrect (didn’t include the proper line/column numbers).
- Various ongoing code-analysis maintenance fixes (too much complexity in many methods).
- moved the source project to Visual Studio 2012; had to migrate the setup project to WiX, since the old VS Setup projects are no longer supported in VS2012.
2012-12-07 Microsoft Ajax Minifier 4.78
- Fix for issue #18924 – using -pretty option left in ///#DEBUG blocks.
- Fix for issue #18980 – bad += optimization caused bug in resulting code. Optimization has been removed pending further review.
“Microsoft Ajax Minifier” への1件の返信