如何将tinymce和所有插件压缩成静态文件?

发布于 2024-12-11 12:05:44 字数 422 浏览 0 评论 0原文

tinymce 的 文档 指出,可以压缩所有 javascript 和组件(我假设包括插件)到单个文件中。他们确实指出了人们可能不希望这样做的原因。

压缩成静态文件

还可以简单地将必要的组件和一些样板代码连接到单个 .js 文件中。但是,如果您想使用其他 TinyMCE 插件或升级 TinyMCE,则始终必须重新创建此文件。您可能还需要配置您的网络服务器来压缩 JavaScript 文件。

但假设一个人确实想要这样做,那么如何实际去做呢? Build.xml 似乎没有提供适当的任务。至少当我尝试加载tiny_mce.js时,插件似乎没有被包含在内。

The documentation for tinymce notes that one can compress all the javascript and components (which I assume includes plugins) into a single file. They do note reasons why one might not want to that as well.

Compressing into a static file

It's also possible to simply concatenate the necessary components and some boilerplate code into a single .js file. However you will always have to recreate this file if you want to use other TinyMCE plugins, or you upgrade TinyMCE. You will also probably want to configure your webserver to compress javascript files.

But assuming one actually did want to do it, how does one actually go about it? Build.xml does does not provide an appropriate task it seems. At least when I tried it the plugins did not seem to be included when I loaded tiny_mce.js.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2024-12-18 12:05:44

有一些非常出色的命令行工具可以实现此目的,但您也可以仅使用文本编辑器轻松完成此操作。最简单的方法是打开每个文件,复制内容,然后将内容粘贴到单个 JS 文件(例如“everything-all-together.js”)中。您需要确保将文件粘贴到单个文件中的顺序与将脚本标记放入 HTML 文档中的顺序相同。将所有文件放在一起后,您可以使用 JSXMin、YUI Compressor 或 Google Closure 等工具。还有一些在线工具可以执行此操作,例如 http://www.minifyjavascript.com/。您可以粘贴未压缩的 JS,然后复制回压缩的 JS。这使得构建过程非常麻烦,但如果您只需要执行一次,就可以实现。

执行此操作的最佳方法是将其作为站点的构建步骤来执行。这意味着当您对 JS 文件进行更改时,您将重建压缩的 JS 文件以包含更改。如果您快速迭代并一遍又一遍地更改文件,这可能是一个麻烦的步骤。您不希望每次保存时都重建压缩文件。您可以通过设置站点的开发和生产模式来解决这个问题。在开发模式下加载时,JS 文件不会组合在一起。完成所有必要的更改后,您将重新运行构建步骤以生成单个压缩的 JS 文件。要从命令行进行缩小,您可能需要使用 Google Closure:https://developers .google.com/closure/compiler/。如果您下载编译器应用程序,您可以执行以下操作:

java -jar compiler.jar some-file.js some-other-file.js >编译.js

这将生成一个名为 Compiled.js 的文件,其中包含缩小格式的 some-file.js 和 some-other-file.js 的内容。您可以根据需要指定任意数量的要编译的文件。事实上,我对 Closure 的说法有点简短,只是说它只是缩小了。它也是极其优化的代码。几乎每个网站都应该始终对所有 JS 执行此操作,除非他们已经在做更好的事情。

There are some really excellent command line tools for this, but you can also do this easily with just a text editor. The simplest way is to just open each file, copy the contents, and paste the contents into a single JS file ("everything-all-together.js", say). You'll need to make sure you paste the files into the single file in the same order you would've put the script tags into the HTML doc. Once you have all the files all together, you can use tools like JSXMin, YUI Compressor, or Google Closure. There are also some tools online that do this, like http://www.minifyjavascript.com/. You can paste in the uncompressed JS and copy back out the compressed JS. This makes the build process really cumbersome, but if you just need to do this once, that will get you there.

The best way to do this is to do it as a build step for the site. That means when you make changes to the JS files, you rebuild the compressed JS file to include the changes as well. This can be a cumbersome step if you're iterating quickly and changing files over and over again. You don't want to have to rebuild the compressed file with each save. You can solve this by setting up development and production modes of the site. When being loaded in development mode, the JS files aren't grouped together. When all the necessary changes are made, you'd rerun the build step to generate the single compressed JS file. To do the minification from the command line, you'd probably want to use Google Closure: https://developers.google.com/closure/compiler/. If you download the compiler app, you can do the following:

java -jar compiler.jar some-file.js some-other-file.js > compiled.js

That will generate a file called compiled.js that includes the contents of some-file.js and some-other-file.js in a minified format. You can specify as many files to compile as you need to. Actually, I'm selling Closure a bit short to say it's just minified. It's also extremely optimized code. Pretty much every site should be doing this to all of there JS all the time unless they're already doing something better.

惟欲睡 2024-12-18 12:05:44

我希望我能让您(和tinymce 文档)正确,但这听起来很像在服务器端组合JavaScript 文件。这意味着获取所有 JS 文件的内容,将它们放入一个文件中并将该文件返回给客户端。

为什么你要这么做?嗯,这应该是显而易见的,但是......您减少了对服务器的 HTTP 请求数量,这总是一件好事。

如何做到这一点?对于所有服务器端语言和框架都有很多解决方案,我建议在 Google 上搜索“[您的语言] javascript minifier”或类似的内容。

希望这有帮助。

I hope I'm getting you (and the tinymce docs) right, but this sounds a lot like combining JavaScript files on the server side. This means taking the contents of all of your JS files, putting them into one file and returning that one to the client.

Why would you do that? Well, this should be obvious, but.. you reduce the number of HTTP requests to your server, which is always a good thing.

How do you do that? There are many solutions out there for all server-side languages and frameworks, I suggest doing a Google search for "[your language] javascript minifier" or something similar.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文