wordpress kratos主题css,js精简去掉无用连接减少网页请求

思想的芦苇是一个文字类网站,没有过多其他功能。

首页加载了不少css和js,访问页面时http请求太多,访问速度慢。这里去掉没必要的css和js,加快访问速度
查看主题的index.php文件,css和js引用分别在头部header.php文件和底部的footer.php文件
header.php改造
<!--?php wp_head(); ?-->加载css引用,但是不会改这个函数,直接去掉。
<!--?php wp_print_scripts('jquery'); ?--> 调用的主题的jquery引用83k,去掉,后面会放到底部去

查看首页源代码可以看到主题引用了不少css样式表。现在只保留这三个加到改位置替换

<link rel='stylesheet' id='awesome-css'  href='http://www.sxdlw.xyz/wp-content/themes/Kratos-2/css/superfish.min.css' type='text/css' media='all' />    //头部导航

<link rel='stylesheet' id='awesome-css' href='网址/主题目录/css/font-awesome.min.css' type='text/css' media='all' />  //图标字体

<link rel='stylesheet' id='bootstrap-css' href='网址/主题目录/css/bootstrap.min.css' type='text/css' media='all' />

<link rel='stylesheet' id='kratos-css' href='网址/主题目录/style.css' type='text/css' media='all' />

路径改造:

<?php bloginfo('template_directory'); ?>获得主题路径

<link rel='stylesheet' id='awesome-css' href='<?php bloginfo('template_directory'); ?>/css/superfish.min.css' type='text/css' media='all' />

<link rel='stylesheet' id='awesome-css' href='<?php bloginfo('template_directory'); ?>/css/font-awesome.min.css' type='text/css' media='all' />

<link rel='stylesheet' id='bootstrap-css' href='<?php bloginfo('template_directory'); ?>/css/bootstrap.min.css' type='text/css' media='all' />

<link rel='stylesheet' id='kratos-css' href='<?php bloginfo('template_directory'); ?>/style.css' type='text/css' media='all' />

2-改造footer.php
<!--?php wp_footer();?-->这个函数加载js引用,主题原引用的以下js。但是不会改这个函数,直接去掉该函数

在<body/>后面只保留这几个js引用

<script type='text/javascript' src="网址/主题/js/jquery.min.js"></script>

<script type='text/javascript' src='网址/主题/js/jquery.stellar.min.js'></script>

<script type='text/javascript' src='网址/主题/js/superfish.js'></script>

<script type='text/javascript' src='网址/主题/js/kratos.js'></script>

目录参考css写法调用路径

扩展:

jquery各版本引用地址参考:http://www.jq22.com/jquery-info122
百度压缩版引用地址:
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
微软压缩版引用地址:
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
官网jquery压缩版引用地址:
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

如果用这些其他域名的引用,额外要增加一个解析时间再下载到本地

亲测,只保留这些css,js就可以了,能保障PC,WAP正常运行。

原文地址:http://www.sxdlw.xyz/wp/173.html

posted @ 2019-07-26 11:00  nohuman  阅读(783)  评论(0编辑  收藏  举报