Web前端培训:15个Javascript压缩工具

Web前端培训:15个Javascript压缩工具

在Web前端开发过程中,我们经常需要编写大量的JavaScript代码,为了提高代码的运行效率和减少文件大小,我们需要对JavaScript代码进行压缩,本文将介绍15个常用的Javascript压缩工具,帮助你快速压缩JavaScript代码。

Web前端培训:15个Javascript压缩工具

1、UglifyJS

UglifyJS是一个非常流行的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用UglifyJS的方法如下:

uglifyjs input.js -o output.js -c --mangle

input.js是需要压缩的JavaScript文件,output.js是压缩后的输出文件,--mangle选项用于混淆变量名。

2、Google Closure Compiler

Google Closure Compiler是一个由谷歌开发的JavaScript编译器,它可以将JavaScript代码转换为浏览器可以执行的低级代码,Google Closure Compiler还具有代码压缩功能,使用方法如下:

Web前端培训:15个Javascript压缩工具

java -jar closure-compiler.jar --language_in=ECMASCRIPT6_STRICT --js output.js --compilation_level ADVANCED --warning_level VERBOSE --define "DEBUG" --formatting PRETTY_PRINTING

output.js是需要压缩的JavaScript文件,其他参数用于控制编译过程。

3、YUI Compressor

YUI Compressor是一个基于CSS预处理器YUI Compressor的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用方法如下:

yuicompressor input.js -o output.js

input.js是需要压缩的JavaScript文件,output.js是压缩后的输出文件。

4、JSMin

Web前端培训:15个Javascript压缩工具

JSMin是一个简单的JavaScript压缩工具,它可以将JavaScript代码压缩到最小,同时保持代码的可读性,使用方法如下:

var f = JSMin(code);

code是需要压缩的JavaScript代码,f是压缩后的代码。

5、Babel

Babel是一个广泛使用的JavaScript编译器,它可以将ES6及以上版本的JavaScript代码转换为向后兼容的JavaScript代码,Babel还具有代码压缩功能,使用方法如下:

npx babel input.js --out-file output.js --presets @babel/preset-env --compact false --minified true --source-maps false --no-comments true --no-stringify false --no-source-map true --comments false --minified false --moduleIdsMode Simple --legacyConstPrecedence true --extractComments false --preserveConst enums minmax maxmind minimize mangle toplevel_rename calcNames names exports localIdent nameShorthand pure beautify arrowThis boolid expString stopVar minExpr number parseInt parseFloat makeRegExp recast regExpToRe replaceTernary computedProp computedKey triggerCallSuffix dynamicImport importNameSpaceSpecifier dynamicImportNamespaceSpecifier importDefaultSpecifier namedExports exportNamedLocals exportNamespaceFromSpecifier exportSpecifierMap exportSpecifierSet functionSent flagInlineRequires inlineRequires localHash localModuleIds moduleIds localNames sourceMaps sourceFileName systemStrings template stringTemplateToString toDefined toStringRaw utilConcat utilIdentity utilUndefined utilDeprecate utilIsObject utilNonEnumerable utilLast utilMath utilNumber utilObject utilParseInt utilPush utilRxutilRefCountedValue utilSet utilWeak utilValueOf varDecl variableDeclarator variables vars arrayLiteral objectLiteral propertyProperty shorthandProperty computedProperty restSpread restElement spreadProperty arguments callExpression newExpression assignment expression statement expressionStatement program program binary arithmetic arithmetic operator unary arithmetic operator logical logical operator bitwise bitwise operator relational relational operator equality equality operator relation and or not instanceof in type of delete inc dec decrement ++ += ++= + += * *= *= % modulo remainder exit log not a not_1 not_1n not_a not_an instanceof is defined hasOwnProperty propertyIsEnumerable constructor prototype valueOf apply bind bindAsArray join iterator entries keys values forEach of fromentries reduce reverse sort sortBy find findIndex from iterate map filter every some every_value join reduce reduceRight flat map flat mapDeep compact pure extract assertType assert assertWarning assertError count countBy sum sumBy max min findKey findValue findIndexBy findIndex findLastIndex findLastIndexOf findLastIndexOfIndexOf index includes includesIndex indexOf lastIndexOf lastIndexOfIndexOf search substr slice sliceWith startWith endWith pad trim trimLeft trimRight reverse split compact_array compactArray sort_object sortObject reverse_array reverseArray join_array joinArray push pop shift unshift splice spliceInsert spliceRemove reverse reverseEach sortBy orderBy sortedIndex sortedIndexBy sortedKey sortedValues group by groupByOrder groupByOrderSort group by each reduce reduceRight forEach forEach_right for_own forIn forAry forOwn of from arguments argumentsToArray argsToArray rest restArguments restArgumentsToArray restSlice restSliceWith restUnshift restPush assign assignTo this yield yieldFrom yieldAll yieldAllStar then chain sequence destructuring mapping extend merge clone deepAssign defaults defaultsDeep partial has defaultToIterableIterable next entries values select pick pickBy pickByOrder get getOrNull getOrUndefined getOrThrow getOrThrowIfNull hasIn hasInWith path pathOr root resolve resolveLookup resolvePath reject rejectWith rejectAll rejectPromise rejectPromiseWith all isEmpty isEmptyWith isNil isNilWith isType isTypeOf like match matchAll matchSome likeIndex likeKey matchValue matchPattern matchPatternWith matches contains containsWith startsWith equals equalsWith indexOf indexOfFrom indexFrom startsWithEndsWith endsWith trim trimStart trimEnd trimBoth escape html jsx regex json xml css url query params headers body content title meta charset referer origin host status location accept acceptCharset acceptEncoding acceptLanguage cookie cookieJar withCredentials proxy auth username password server key certificate ca cert passphrase clientkey clientcert strictSSL host name port domain protocol http https ws wss request response on stream pipe fetch setTimeout setTimeoutClear clearInterval clearImmediate console log warn error assert print info debug time now performance mark markTime timeEnd timeStamp timezone date format dateAdd dateSubtract dayStart dayEnd hoursMinutesSeconds milliseconds days weeks months years add subtract round up down multiply divide abs ceil floor log base random randomBytes randomInt randomNormal randomExponential randomGlow randomGlowShuffle round halfPi PI e E INFINITY NAN MAX_SAFE_INTEGER MIN_SAFE_INTEGER MAX_VALUE MIN_VALUE Number BigInt Int8Array Uint8Array Uint8ClampedArray Int16Array Int32Array Float32Array Float64Array BigInt64Array BigUint64Array Date RegExp ArrayBuffer DataView Set Map WeakMap WeakSet Proxy Intl Error Event Promise Generator GeneratorFunction Function AsyncFunction ReadableStream WritableStream Transform Duplex Stream pipeline pipelineRate through take takeWhile takeEvery takeLatest throttle throttleTimely map mapValues mapEntries for await of yieldAwaitOf promiseAll promiseResolve allSettled race raceOnce settle settlePromise any some every someValue someValues findIndex fromEntries findIndexFrom findLastIndex findLastIndexFrom findKey findValue indexBy indexByOrder indexByOrderSort indexByKey indexByValue join joinWith joinWithSeparator split splitWith splitLimit remove removeAt removeAll removeFrom splice spliceInsert spliceRemove reverse reverseEach sortBy orderBy sortedIndex sortedIndexBy sortedKey sortedValues group by groupByOrder groupByOrderSort group by each reduce reduceRight forEach forEach_right for_own forIn forAry forOwn of from arguments argsToArray rest restArguments restArgumentsToArray restSlice restSliceWith restUnshift restPush assign assignTo this yield yieldFrom yieldAll yieldAllStar then chain sequence destructuring mapping extend merge clone deepAssign defaults defaultsDeep partial has defaultToIterableIterable next entries values select pick pickBy pickByOrder get getOrNull getOrUndefined getOrThrow getOrThrowIfNull hasIn hasInWith path pathOr root resolve resolveLookup resolvePath reject rejectWith rejectAll rejectPromise rejectPromiseWith all isEmpty isEmptyWith isNil isNilWith isType isTypeOf like match matchAll matchSome likeIndex likeKey matchValue matchPattern matchPatternWith matches contains containsWith startsWith equals equalsWith indexOf indexOfFrom indexFrom startsWithEndsWith endsWith trim trimStart trimEnd trimBoth escape html jsx regex json xml css url query params headers body content title meta charset referer origin host status location accept acceptCharset acceptEncoding acceptLanguage cookie cookieJar withCredentials proxy auth username password server key certificate ca cert passphrase clientkey clientcert strictSSL host name port domain protocol http https ws wss request response on stream pipe fetch setTimeout setTimeoutClear clearInterval clearImmediate console log warn error assert print info debug time now performance mark markTime timeEnd timeStamp timezone date format dateAdd dateSubtract dayStart dayEnd hoursMinutesSeconds milliseconds days weeks months years add subtract round up down multiply divide abs ceil floor log base random randomBytes randomInt randomNormal randomExponential randomG

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/134179.html

Like (0)
Donate 微信扫一扫 微信扫一扫
K-seo的头像K-seoSEO优化员
Previous 2023-12-16 11:57
Next 2023-12-16 12:00

相关推荐

  • html怎么for循环语句

    在HTML中,我们不能直接使用for循环语句,因为HTML是一种标记语言,它不具备编程语言的功能,我们可以使用JavaScript或者后端模板引擎(如PHP、Python等)来实现循环功能,下面我将分别介绍如何使用JavaScript和后端模板引擎实现for循环。使用JavaScript实现for循环在HTML中,我们可以使用&amp……

    2024-04-06
    0136
  • 前端主机运营考试题库分享

    分享前端主机运营考试题库,帮助考生提升技能,提高通过率。

    2024-03-13
    0181
  • viahtml代码怎么用

    HTML,全称为超文本标记语言(HyperText MarkupLanguage),是用于创建网页的标准标记语言,它可以用来组织网页的内容 —— 包括文本、图片、链接等元素 —— 并定义这些元素的布局和样式,HTML代码是一种纯文本格式,可以使用任何文本编辑器编写,然后将其保存为.html文件。1\. HTML基础HTML文档由一系列……

    2024-01-05
    0131
  • html5css3显示隐藏「css控制显示隐藏」

    哈喽!相信很多朋友都对html5css3显示隐藏不太了解吧,所以小编今天就进行详细解释,还有几点拓展内容,希望能给你一定的启发,让我们现在开始吧!怎么样实现点击按钮显示一个div,页面上其他的内容全部隐藏1、-- 实现点击按钮显示一个div,页面上其他的内容全部隐藏。再点击返回按钮,div隐藏,页面上所有的内容再显示出来。

    2023-12-09
    0132
  • 如何实现a标签在JS中的悬停效果?

    理解<a> 标签与 JavaScript 悬停效果在网页开发中,<a> 标签(超链接)是最常用的 HTML 元素之一,它不仅用于创建指向其他页面或资源的链接,还可以通过结合 CSS 和 JavaScript 实现丰富的交互效果,本文将详细探讨如何使用 JavaScript 实现<a……

    2024-11-18
    05
  • 如何使用JavaScript阻止a标签的默认跳转行为?

    使用JavaScript阻止<a>标签的默认跳转行为在网页开发中,有时候我们需要通过JavaScript来阻止链接(<a>标签)的默认跳转行为,这通常用于处理一些需要在点击后执行特定操作的情况,例如发送Ajax请求、显示模态窗口等,下面将详细介绍如何实现这一功能,1. 基本概念默认情况下……

    2024-11-19
    02

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入