在保持元素/样式/脚本关系的同时缩小整个目录? [英] Minify an Entire Directory While Keeping Element/Style/Script Relationships?

查看:107
本文介绍了在保持元素/样式/脚本关系的同时缩小整个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前是否存在可以缩小整个项目目录的解决方案?更重要的是,是否存在任何可以缩短类名,ID并在所有文档中保持一致的解决方案?

Do any solutions currently exist that can minify an entire project directory? More importantly, do any solutions exist that can shorten classnames, id's, and keep them consistent throughout all documents?

可以改变这一点的东西:

Index.html ---

Index.html ---

<div class="fooBar">
  <!-- Code -->
</div>

Styles.css ---

Styles.css ---

.fooBar { 
  // Comments and Messages
  background-color: #000000; 
}

Index.js ---

Index.js ---

$(".fooBar").click( function () { 
  /* More Comments */
  alert( "fooBar" ); 
});

为此:

Index.html ---

Index.html ---

<div class="a"></div>

Styles.css ---

Styles.css ---

.a{background-color:#000;}

Index.js ---

Index.js ---

$(".a").click(function(){alert("fooBar");});

推荐答案

您要查找的不是压缩,而是压缩.按定义最小化 会删除空格,因为缩短标识符会更改接口,从而可能破坏依赖于该接口的外部脚本.因此,缩小在本质上比压缩更安全",尽管在封闭的系统(即封装的Web应用程序)中,压缩可能是个好主意.

What you're looking for isn't minifying, but compression. Minifying by definition only removes whitespace, since shortening identifiers alters the interface, potentially breaking external scripts that depend on it. For this reason, minifying is inherently 'safer' than compression, although in a closed system (ie. an encapsulated web app), compression can be a good idea.

对于Java ,大​​多数人使用 YUI Compressor 迪恩·爱德华兹的包装工.

For Javascript, most people use the YUI Compressor or Dean Edwards' Packer.

对于CSS ,有很多工具可以优化"样式,但是我不知道有什么工具可以缩短类名.造成这种情况的原因可能有几种:

For CSS, there are plenty of tools for 'optimizing' the styles, but I don't know of any that shorten class names as well. The reasons for this could be several:

  1. 要压缩CSS文件,脚本将需要知道所有包含该文件的HTML文件,以便更改其中的类和id引用.根据您网站的大小和结构,他可能并不重要.
  2. 压缩后,语义HTML变得不那么可读,因为<span class="image_caption">变成了<span class="a12">,或者更糟的是,变成了<p id="a12">.
  1. To compress a CSS file, the script would need to know all HTML files that include it, in order to change the class and id references within them. Depending on your web site's size and structure, his could be non-trivial.
  2. After compression, semantic HTML becomes less readable, as <span class="image_caption"> turns into <span class="a12">, or worse yet, <p id="a12">.

绝对有可能做您所描述的事情(我实际上正在研究制作的个人CMS/框架),但要保持其可维护性,它可能具有成为结构紧密的CMS的组成部分,每当发布新更改时,都会压缩幕后"的所有文件,同时保留所有原始文件,以便可以对站点进行整体维护.

It would definitely be possible to do something like what you describe (and I'm actually working on a personal CMS/framework that will), but for it to be maintainable, it would probably have to be an integrated part of a tightly structured CMS, compressing all files 'behind the scenes' whenever a new change is published, while keeping all the original files so the site can be maintained as a whole.

这篇关于在保持元素/样式/脚本关系的同时缩小整个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆