gpt4 book ai didi

javascript - 为 Web 应用程序仅组合必要的 css 和 js 的任何好方法

转载 作者:行者123 更新时间:2023-11-29 10:23:53 26 4
gpt4 key购买 nike

我一直在改进 Web 应用程序前端的结构,并完成了合并和缩小 css/js 文件、版本文件以及构建一些模板等工作。但是我正在查看一些网络工具,它说有大量未使用的 js/css。有什么建议吗 - 发现完全必要的代码 - 为页面合并、缩小和版本控制正确的代码我主要是在寻找一个合乎逻辑的建议,任何代码示例都会很棒。我专门在 apache 上使用 python、猎豹模板、yui-compressor、版本控制修改时间、mod_rewrite 和 gzip

最佳答案

查看 Dust-Me Selectors用于简化 CSS 的 Firefox 扩展:

Dust-Me Selectors is a Firefox extension (for v1.5 or later) that finds unused CSS selectors.

It extracts all the selectors from all the stylesheets on the page you're viewing, then analyzes that page to see which of those selectors are not used. The data is then stored so that when testing subsequent pages, selectors can be crossed off the list as they're encountered.

You can test pages individually, or spider an entire site, and you'll end up with a profile of which selectors are not used anywhere.

对于 JavaScript,请查看 Google Closure Compiler它可以计算代码中的相互依赖性并删除冗余。

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

关于javascript - 为 Web 应用程序仅组合必要的 css 和 js 的任何好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6039333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com