如何将所有 css 文件放在一个文件中,并将所有 javascript 文件放在一个文件中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10520302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put all css files in one file and all javascript files in one file
提问by William Kinaan
When I want to include any new CSS
file or any new JS
file, I put it in the header as this
当我想包含任何新CSS
文件或任何新JS
文件时,我将它放在标题中,如下所示
css file
css文件
<link rel="stylesheet" href="<?php echo URL; ?>public/css/header.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/index.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/footer.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/signup.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/contactUs.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/option.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/question.css" />
<link rel="stylesheet" href="<?php echo URL; ?>public/css/profile.css" />
js file
js文件
<script src=<?php echo URL . "public/Js/profile.js" ?>></script>
<script src=<?php echo URL . "public/Js/cell.js" ?>></script>
<script src=<?php echo URL . "public/Js/place.js" ?>></script>
<script src=<?php echo URL . "public/Js/ontology.js" ?>></script>
<script src=<?php echo URL . "public/Js/informativeObject.js" ?>></script>
<script src=<?php echo URL . "public/Js/question.js" ?>></script>
I want something like
我想要类似的东西
<header>
include all css
include all js
</header>
回答by Wintermute
回答by Gio Borje
For CSS, you could use @import
:
对于 CSS,您可以使用@import
:
HTML with CSS:
带有 CSS 的 HTML:
<style type="text/css">
@import url('index.css');
@import url('footer.css');
</style>
Standalone CSS:
独立 CSS:
@import url('index.css');
@import url('footer.css');
Browsers include JavaScript as a #include
AFAIK so there's no better way than including them all through <script>
tags or by using Wintermute's example of a JS minifier.
浏览器将 JavaScript 作为#include
AFAIK包含在内,因此没有比通过<script>
标签或使用 Wintermute 的 JS 缩小器示例将它们全部包含在内更好的方法。
Edit: JSMinby Crockford is a CLI utility that you can use if you want to work with it offline.
编辑:Crockford 的JSMin是一个 CLI 实用程序,如果您想离线使用它,您可以使用它。
回答by symcbean
Assuming you've got an array of files (using the local filesystem path)
假设你有一个文件数组(使用本地文件系统路径)
print "<style type='text/css'>\n";
showall($css);
print "</style>";
function showall($filelist)
{
foreach ($filelist as $fname) {
print file_get_contents($fname) . "\n";
}
}