Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of optimizing wordpress blog

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method of optimizing wordpress blog, the article is very detailed, has a certain reference value, interested friends must read it!

How to optimize wordpress blog?

My optimization steps are:

1. Compress CSS and JS files, and modify some plug-ins to optimize the page loading process

Generally speaking, plug-ins that need to load JS or CSS will have two lines of code: add_action ("wp_head", "xxxx") or add_action ("wp_footer", "xxxx"). The purpose is to insert your own script or style into the wp_head () and wp_footer () of the theme, so that the plug-in can work properly (note to those who report that the plug-in is activated but can't see the effect. I've observed that a considerable number of people use themes that don't load plug-in scripts properly, and these two functions are missing.

Let's get back to the point. We need to optimize the loading process, that is, traffic shaping, move the CSS file to head (100% plug-ins can do this, don't worry), and put the JS file at the end of the page. We can delete the sentence add_action (xxxx) and manually insert the required files into the theme template.

two。 Compress CSS and JS to shorten file loading time

People who often write scripts in jQuery should be aware that the uncompressed version of the jQuery library (1.3.2) is about 120K, but the min version is only 56K. Because the min version of the jQuery library is compressed by YUI Compressor, it removes comments, useless spaces, and line breaks from the code. We can also use YUI to compress our scripts, with a compression ratio of 30% to 70%. Due to the complexity of the software version of the YUI installation process, there is an online version.

CSS compression is relatively simple, that is, the removal of line breaks, spaces and comments, you can use online tools to compress it. However, the topic information in which the style.css header of the topic is commented out cannot be deleted, otherwise the theme may not be normal.

For CSS compression, many people use PHP compression. Write a file named style.css.php with the following contents:

The code is as follows:

If (extension_loaded ('zlib') and! ini_get (' zlib.output_compression') and ini_get ('output_handler')! =' ob_gzhandler' and ((version_compare (phpversion (), '5.0,' > =') and ob_get_length () = = false) or ob_get_length () = false) {ob_start ('ob_gzhandler');} else {ob_start () } / / check whether there are Gzip-related modules, and if so, use Gzip to transmit them. If the host has Apache mod_deflate.c or other equivalent modules, you can not write this @ header ("Cache-Control: public"); @ header ("Pragma: cache"); / / cache file $expiresOffset = 3600240365 leading header ("Vary: Accept-Encoding"); @ header ("Expires:". Gmdate ("D, d M Y H:i:s", time () + $expiresOffset). "GMT"); / / set the cache time @ header ('Content-Type: text/css'); / / declare the file type $cssdata = file_get_contents (' style.css'); / / read the contents of style.css $cssdata = preg_replace (array ('/\ s *) [ :\ {\}])\ echo cssdata;// output code,'/ [\ t\ n\ r] /','/\ /\ *. +?\ *\ /'), array ('\\ 1comment,','), $cssdata); / / clear comments and line feeds

Put this file in the theme folder and change the loading code of the theme CSS to

The code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report