Plugin Directory

Changeset 2113474


Ignore:
Timestamp:
06/27/2019 08:50:27 AM (7 years ago)
Author:
grfstudio
Message:

Optimized prefetching script

Location:
wp-admin-cache/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-admin-cache/trunk/index.js

    r2050442 r2113474  
    22    if (urls.length == 0) return;
    33
    4     var countDown = 0;
     4    var dbI = urls.indexOf("index.php");
     5    if (dbI > 0) {// priority for dashboard
     6        urls.splice(0, 0, urls.splice(dbI, 1)[0]);
     7    }
     8
     9    var urlIndex = 0;
     10    var expiration = 0;
    511    var refresh = 0;
    612
    713    function exec() {
    8         countDown--;
    9         if (countDown < 0) {
    10             countDown = 60;
    11             jQuery.ajax({
    12                 url: urls[0],
    13                 method: 'POST',
    14                 data: {'wp_admin_cache_prefetch': 1, 'wp_admin_cache_refresh': refresh}
    15             }).done(function (data) {
    16                 if (data.indexOf("prefetched") == 0) {
    17                     var expiration = data.split(':')[1] * 1;
    18                     if (expiration < 60) {
    19                         countDown = expiration - 2;
    20                         refresh = 1;
    21                     }
    22                 }
    23                 else {
    24                     for (var i = 1; i < urls.length; i++) {
    25                         function exec2(url) {
    26                             jQuery.ajax({
    27                                 url: url,
    28                                 method: 'POST',
    29                                 data: {'wp_admin_cache_prefetch': 1, 'wp_admin_cache_refresh': refresh}
    30                             }).done(function (data) {
    31 
    32                             });
    33                         }
    34                         if (urls[i] != '') exec2(urls[i]);
    35                     }
    36                     refresh = false;
    37                 }
    38             });
     14        if (urls.length == 0) return;
     15        if (urlIndex == urls.length) {
     16            urlIndex = 0;
     17            var delay = expiration - 10000;
     18            if (delay < 2000) delay = 2000;
     19            expiration = 0;
     20            setTimeout(exec, delay);
     21            refresh = 1;
     22            return;
    3923        }
    40 
     24        jQuery.ajax({
     25            url: urls[urlIndex],
     26            method: 'POST',
     27            data: {'wp_admin_cache_prefetch': 1, 'wp_admin_cache_refresh': refresh}
     28        }).done(function (data) {
     29            if (data.indexOf("prefetched") == 0 || data.indexOf("prefetching") == 0) {
     30                var exp = data.split(':')[1] * 1000;
     31                if (exp < expiration || expiration == 0) expiration = exp;
     32               
     33            }
     34            urlIndex++;
     35            setTimeout(exec, 10);
     36        }).fail(function (jqXHR, textStatus, errorThrown) {
     37            urlIndex++;
     38            setTimeout(exec, 10);
     39        });
    4140
    4241
    4342    }
    44     setInterval(exec, 1000);
     43    jQuery(exec);
    4544
    4645}
  • wp-admin-cache/trunk/index.php

    r2060162 r2113474  
    55  Plugin URI: https://www.wpadmincache.com
    66  Description: The first cache plugin for WordPress admin area
    7   Version: 0.2.2
     7  Version: 0.2.3
    88  Author: Grf Studio
    99  Author URI: https://www.grfstudio.com
     
    5858    function init() {
    5959        add_options_page('WP Admin Cache', 'WP Admin Cache', 'manage_options', 'wp-admin-cache', array($this, 'options_page'));
    60         wp_enqueue_script('wp-admin-cache-script', plugin_dir_url(__FILE__) . 'index.js', array(), '0.2.2');
    61         wp_enqueue_style('wp-admin-cache-style', plugin_dir_url(__FILE__) . 'index.css', array(), '0.2.2');
     60        wp_enqueue_script('wp-admin-cache-script', plugin_dir_url(__FILE__) . 'index.js', array(), '0.2.3');
     61        wp_enqueue_style('wp-admin-cache-style', plugin_dir_url(__FILE__) . 'index.css', array(), '0.2.3');
    6262        $session = wp_get_session_token();
    6363        if (!isset($_COOKIE['wp-admin-cache-session']) || $_COOKIE['wp-admin-cache-session'] != $session) setcookie('wp-admin-cache-session', $session, 0, admin_url());
     
    157157        set_transient($this->currentCaching, $content, 60 * $duration);
    158158        if (isset($_POST['wp_admin_cache_prefetch'])) {
    159             return 'prefetching';
     159            return 'prefetching:'.($this->settings['duration'] * 60);
    160160        }
    161161        return $content;
  • wp-admin-cache/trunk/readme.txt

    r2060162 r2113474  
    11=== WP Admin Cache ===
    22Contributors: grfstudio
    3 Tags: admin cache, admin performance, admin speed, slow admin
    4 Stable tag: 0.2.2
     3Tags: admin cache, admin performance, admin speed, slow admin, woocommerce performance, slow woocommerce
     4Stable tag: 0.2.3
    55Requires PHP: 5.6
    66Requires at least: 4.6
    7 Tested up to: 5.1
     7Tested up to: 5.2
    88License: GPLv2 or later
    99
     
    1414This lightweight plugin caches the most visited pages in the admin area; it uses ajax to prefetch the pages and stores them on the server for each user.
    1515
    16 The plugin is useful for sites with many installed plugins, which often make the administrative section very slow.
     16The cache is useful for sites with many installed plugins, which often make the administrative section very slow, especially in the case of woocommerce with many displayed products.
     17
    1718
    1819== Installation ==
     
    4142
    4243== Changelog ==
     44
     45= 0.2.3 =
     46
     47* Changed prefetching script: optimized page load
    4348
    4449= 0.2.2 =
Note: See TracChangeset for help on using the changeset viewer.