所有的PHP页面包括整套CSS和JS,高效? [英] All PHP pages include the entire set of CSS and JS, efficient?

查看:67
本文介绍了所有的PHP页面包括整套CSS和JS,高效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会总结一下。

我有几个PHP页面,它们都有以下格式:

I have a few PHP pages, all of them have the following format:

<?php
include "header.php";
?>
INSERT PAGE SPECIFIC MATERIAL HERE
<?php
include "footer.php" ?>

header.php

header.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- Main CSS -->
    <link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
    <navmenu></navmenu>

footer.php

footer.php

    <footer></footer>
    <!-- jQuery -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <!-- Theme JavaScript -->
    <script src="js/main.js"></script>

</body>
</html>

我是PHP的新用户,不知道这是否是有效构建PHP文件的正确方法,因为我的问题是:

I am new to PHP and not sure if this is the correct way to efficiently structure my PHP files because my concerns are:


  1. 每个PHP页面现在加载相同的导航菜单和页脚。 这是准备好的。但是,它还会将所有CSS和JS加载到,即使有很多行的CSS和JS,它在那个特定的页面中实际上没有用,但在其他页面中使用。这是一个需要关注的问题,如果是的话,我们应该怎么做呢?

  2. 我应该分离我的main.js,style.css,header.php和footer.php每个PHP页面加载正文函数所需的最小量?

  3. 处理此情况时的标准做法是什么?

  1. Each PHP page now loads the same navigation menu and footer. This is intended and is ok. However, it also loads ALL CSS and JS together, even when there are lots of lines of CSS and JS where it is not actually useful in that specific page BUT used in other pages. Is this a need for concern and if yes what ways should we go about doing this?
  2. Should I separate my main.js, style.css, header.php and footer.php so that each PHP page loads the minimum amount needed for the body functions?
  3. What is the standard practice when dealing with this case?

$ b $

推荐答案


如果您能给出一些建议,我应该分离我的main.js,style.css,header.php和footer.php,以便每个PHP页面加载身体函数所需的最小量?

Should I separate my main.js, style.css, header.php and footer.php so that each PHP page loads the minimum amount needed for the body functions?

您应该为整个网站创建一个css文件和一个js文件。不要使用php文件作为css,因为:

You should create ONE css file and ONE js file for your entire web site. don't use php file act as css because:


  1. 如果你有高访问网站,最好有一个css和js文件。因为它是一个直接文件。但是当你通过php文件创建css或js时,php需要计算。也许你认为这是非常低的水平计算,但如果你需要良好的性能在高访问的网站,你需要看到一切。

  1. If you have high visit web site, It's better to have ONE css and js file. Because It's a direct file. but when you are creating css or js by php file, php need to calculate. Maybe you think it's very low level calculate but if you need good performance on high visited web site, you need to see everything.

如果你创建css和js文件由php,有时你需要导入多个js或css文件。谁知道?也许它让你使用10 js和10 css在你的头标签内!

If you create css and js file by php, sometimes you need to import multiple js or css file. Who knows? maybe it make you to use 10 js and 10 css inside your head tag! and It's bad for SEO.

不要担心一个css或js文件大小。

Don't worry about one css or js file size. It's better with lower size but you can still create 100KB css or js file without SEO problem.

您可以为所有媒体创建一个css文件。打印包括。无论您使用多个还是单个文件,如果需要,总是在同一个文件中使用 @media print {}

You can have one css file for all media. print included. Doesn't matter you are using multiple or single file, always use @media print{} inside the same file if you need it.

ONE css和js文件可以全局缓存。即使您不需要css或js文件,全局css和js文件也已缓存。

ONE css and js file can globally cache. even if you don't need the css or js file, the global css and js file are already cached.

我不是说一个css和js文件总是很好的想法,但它有最大的好处。

I'm not saying ONE css and js file is always great idea but it has the most benefit.

这篇关于所有的PHP页面包括整套CSS和JS,高效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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