{"id":3051,"date":"2019-02-18T16:42:40","date_gmt":"2019-02-18T08:42:40","guid":{"rendered":"https:\/\/www.ookangzheng.com\/?p=3051"},"modified":"2020-05-24T15:58:33","modified_gmt":"2020-05-24T07:58:33","slug":"wordpress-speed-tweak","status":"publish","type":"post","link":"https:\/\/www.ookangzheng.com\/wordpress-speed-tweak\/","title":{"rendered":"WordPress speed tweak"},"content":{"rendered":"\n

Website load speed greatly impacts your website search rankings, bounce rates, and overall user experience. I will list out several ways to improve it.<\/p>\n\n\n\n

List will continuing update <\/strong><\/p>\n\n\n\n

  1. HTTPS<\/li>
  2. Optimze<\/g> Image<\/li>
  3. Gzip <\/li>
  4. CDN<\/li>
  5. Cache<\/li>
  6. Anycast DNS <\/li>
  7. TTFB\uff08Time To First Byte)<\/li><\/ol>\n\n\n\n

    HTTPS<\/h3>\n\n\n\n

    Now is 2019 era, Google and Mozilla push internet community to use HTTPS, HSTS to enhance security and improve SEO ranking. So just grab a free Let’s Encrypt SSL and you are ready to go. Also, remember to donate some money to Let’s encrypt if you think is helpful. ( no affiliate).<\/p>\n\n\n\n

    Optimize Image<\/h3>\n\n\n\n

    I recommend to use some free wordpress plugin to optimize your thumbnail and add lazy loading. <\/p>\n\n\n\n

    GZIP<\/h3>\n\n\n\n

    I have 2 solution for common server
    To enable gzip compression simply add these lines to your .htaccess file:<\/p>\n\n\n\n

    #Gzip\n<IfModule mod_deflate.c>\n  # Compress HTML, CSS, JavaScript, Text, XML and fonts\n  AddOutputFilterByType DEFLATE application\/javascript\n  AddOutputFilterByType DEFLATE application\/rss+xml\n  AddOutputFilterByType DEFLATE application\/vnd.ms-fontobject\n  AddOutputFilterByType DEFLATE application\/x-font\n  AddOutputFilterByType DEFLATE application\/x-font-opentype\n  AddOutputFilterByType DEFLATE application\/x-font-otf\n  AddOutputFilterByType DEFLATE application\/x-font-truetype\n  AddOutputFilterByType DEFLATE application\/x-font-ttf\n  AddOutputFilterByType DEFLATE application\/x-javascript\n  AddOutputFilterByType DEFLATE application\/xhtml+xml\n  AddOutputFilterByType DEFLATE application\/xml\n  AddOutputFilterByType DEFLATE font\/opentype\n  AddOutputFilterByType DEFLATE font\/otf\n  AddOutputFilterByType DEFLATE font\/ttf\n  AddOutputFilterByType DEFLATE font\/woff\n  AddOutputFilterByType DEFLATE image\/svg+xml\n  AddOutputFilterByType DEFLATE image\/x-icon\n  AddOutputFilterByType DEFLATE text\/css\n  AddOutputFilterByType DEFLATE text\/html\n  AddOutputFilterByType DEFLATE text\/javascript\n  AddOutputFilterByType DEFLATE text\/plain\n  AddOutputFilterByType DEFLATE text\/xml\n\n  # Remove browser bugs (only needed for really old browsers)\n  BrowserMatch ^Mozilla\/4 gzip-only-text\/html\n  BrowserMatch ^Mozilla\/4\\.0[678] no-gzip\n  BrowserMatch \\bMSIE !no-gzip !gzip-only-text\/html\n  Header append Vary User-Agent\n<\/IfModule>\n# End Gzip\n\n# If mod_deflate doesn\u2019t work on your server you can use mod_gzip\n<IfModule mod_gzip.c>\n  mod_gzip_on Yes\n  mod_gzip_dechunk Yes\n  mod_gzip_item_include file .(html?|txt|css|js|php|pl)$\n  mod_gzip_item_include handler ^cgi-script$\n  mod_gzip_item_include mime ^text\/.*\n  mod_gzip_item_include mime ^application\/x-javascript.*\n  mod_gzip_item_exclude mime ^image\/.*\n  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*\n<\/IfModule>\n \n#Gzip\n<IfModule mod_headers.c>\n  Header set Connection keep-alive\n<\/IfModule><\/code><\/pre>\n\n\n\n
    \/\/ Nginx.conf\n# Enable Gzip compression.\ngzip on;\n\n# Disable Gzip on IE6.\ngzip_disable \"msie6\";\n\n# Allow proxies to cache both compressed and regular version of file.\n# Avoids clients that don't support Gzip outputting gibberish.\ngzip_vary on;\n\n# Compress data, even when the client connects through a proxy.\ngzip_proxied any;\n\n# The level of compression to apply to files. A higher compression level increases\n# CPU usage. Level 5 is a happy medium resulting in roughly 75% compression.\ngzip_comp_level 5;\n\n# The minimum HTTP version of a request to perform compression.\ngzip_http_version 1.1;\n\n# Don't compress files smaller than 256 bytes, as size reduction will be negligible.\ngzip_min_length 256;\n\n# Compress the following MIME types.\ngzip_types\n\tapplication\/atom+xml\n\tapplication\/javascript\n\tapplication\/json\n\tapplication\/ld+json\n\tapplication\/manifest+json\n\tapplication\/rss+xml\n\tapplication\/vnd.geo+json\n\tapplication\/vnd.ms-fontobject\n\tapplication\/x-font-ttf\n\tapplication\/x-web-app-manifest+json\n\tapplication\/xhtml+xml\n\tapplication\/xml\n\tfont\/opentype\n\timage\/bmp\n\timage\/svg+xml\n\timage\/x-icon\n\ttext\/cache-manifest\n\ttext\/css\n\ttext\/plain\n\ttext\/vcard\n\ttext\/vnd.rim.location.xloc\n\ttext\/vtt\n\ttext\/x-component\n\ttext\/x-cross-domain-policy;\n  # text\/html is always compressed when enabled.<\/code><\/pre>\n\n\n\n

    CDN<\/h3>\n\n\n\n

    There are three main types of content delivery networks: <\/p>\n\n\n\n

    1. Content Service Protocols: <\/strong>These are fully managed hosted networks designed to provide users access to the website files. The services we\u2019re discussing in this blog post falls under this type.<\/li>
    2. Peer-to-peer CDNs: <\/strong>With a very small setup and running cost, peer-to-peer (P2P) setups work between personal computers and therefore are not great for hosting your website\u2019s files. BitTorrent<\/a> is a popular example of a Peer-to-peer network.<\/li>
    3. Private CDNs: <\/strong>Alternatively, if you\u2019re not satisfied with available services, you can create your own private service. This means you have to create and manage own global network of servers to serve your static files.<\/li><\/ol>\n\n\n\n
      \"Benefits\"\/<\/figure>\n\n\n\n

      But today we will focus on Free CDN services<\/p>\n\n\n\n

      1. Jetpack plugin, enable Photon image CDN FREE<\/li>
      2. Host your domain at Cloudflare.com<\/a> and active its proxy will slightly speed you up<\/li>
      3. Coral CDN<\/a> (p2p)<\/li>
      4. jsDELIVR<\/g><\/a> If you develop own WordPress theme, consider use jQuery or Bootstrap CDN with it.<\/li>
      5. cdnjs<\/a><\/g> same as jsdelivr<\/li><\/ol>\n\n\n\n

        Cache<\/h3>\n\n\n\n
        1. WP Super Cache<\/a> plugin <\/li>
        2. Breeze<\/a> plugin<\/li><\/ol>\n\n\n\n

          Anycast DNS provider<\/h3>\n\n\n\n
          1. Cloudflare<\/a><\/li>
          2. Hurricane Electric<\/a><\/li>
          3. Freedns Afraid <\/a><\/li>
          4. NS1<\/a><\/li>
          5. CloudDNS.net<\/a><\/li>
          6. 1984 DNS<\/a><\/li>
          7. DYNU<\/a><\/li><\/ol>\n\n\n\n
            \"DNS
            DNS Speed Comparison Report by www.solvedns.com<\/figcaption><\/figure>\n\n\n\n

            TTFB<\/h3>\n\n\n\n

            \u201cTime spent waiting for the initial response, also known as the Time To First Byte. This time captures the latency of a round trip to the server in addition to the time spent waiting for the server to deliver the response.\u201d<\/em><\/p>\n\n\n\n

            To put it simply, TTFB is the amount of time from the moment you navigate to a web page to the moment it starts rendering.<\/p>\n\n\n\n

            Google recommends a TTFB under 200ms<\/a>.
            Cloudflare says 
            you should stop worrying about TTFB<\/a>.
            What will affect TTFB
            <\/p>\n\n\n\n