Problems with CSS changing in every request - Popup Pro

Dear Sir/Madam

We are users of the Popup Pro plug in. We own a licence.

We have noticed that our css cache (autoptimize) was increasing in disk size. We investigated and we reached that WPMU Popup pro is changing every request the css files (through the function _prepare_js_or_css in functions-wpmulib.php) This is generting that autoptimize identifies a new css file (even though nothing changed really) and generating a new cache file.

This happens for "every request". We have good traffic, and this generate that we need to control cache files.

Can you explain why you use this css practice and how can I disable it.

Regards

  • Ivan

    Hey there Alejandro,

    Hope you are having great week so far!

    The function you mention

    function _prepare_js_or_css

    Is located in
    /wp-content/plugins/popover/inc/external/wpmu-lib/inc/class-thelib.php

    I didn't find file named "functions-wpmulib.php"
    Also what this function does as far as I can understand out of the context of the code - because I don't know it in depth, is to check and preload any css or js for the pop-up before preview so it can be load instantly.

    Doesn't autoptimize have the options to clear the cache after period of time?

    How much space taken do we talk here?
    It is normal caching to take a piece of your storage.

    Thanks,
    Ivan

  • Alejandro

    Hi Ivan

    Sorry to hear you cannot find the files.

    /plugins/popover/inc/external/wpmu-lib/functions-wpmulib.php
    Version: 4.7.0.4
    WDP ID: 123

    Try to find it with that information.

    The problem is that the function is "changing" the css code for every request. Caching systems (in this case autoptimize) identify this code changes, and generate new cache.

    Again...is a new file for every request.....and I have lots of requests....Im getting a disk problem. Even though I can solve it, erasing cache after X % of disk...What your plugin is doing is wrong.

    This is bad coding. You know which is the problem, here is the guilty piece of code:

    protected function load_styles() {
    		static $Code = array();
    
    		if ( ! isset( $Code[ $this->id ] ) ) {
    			$styles = apply_filters( 'popup-styles', array() );
    			$details = $styles[$this->style];
    
    			$Code[ $this->id ] = '';
    			$tpl_file = $details->dir . 'style.css';
    
    			if ( file_exists( $tpl_file ) ) {
    				ob_start();
    				include( $tpl_file );
    				$Code[ $this->id ] = ob_get_contents();
    				ob_end_clean();
    
    				$Code[ $this->id ] = str_replace( '#messagebox', '#' . $this->code->id, $Code[ $this->id ] );
    				$Code[ $this->id ] = str_replace( '%styleurl%', $details->url, $Code[ $this->id ] );
    				$Code[ $this->id ] = str_replace( '#000001', $this->code->color1, $Code[ $this->id ] );
    				$Code[ $this->id ] = str_replace( '#000002', $this->code->color2, $Code[ $this->id ] );
    			}
    			$custom_css = $this->custom_css;
    			$custom_css = str_replace( '#popup', '#' . $this->code->id, $custom_css );
    			$custom_css = str_replace( '#messagebox', '#' . $this->code->id, $custom_css );
    			$custom_css = str_replace( '%styleurl%', $details->url, $custom_css );
    			$Code[ $this->id ] .= $custom_css;
    		}
    		return $Code[ $this->id ];
    	}

    Can you believe it?

    You are replacing the #messagebox for every line of the CSS for every request , applying the resource consuming function str_replace.

    This code is awful. Its slowing down my site, and is generating cache problems.

    Please put someone to work on this.

    Regards,

  • Vinod Dalvi

    Hi Alejandro,

    Thank you for your reply.

    Sorry to tell you but i also didn't find the file functions-wpmulib.php on the following path in the latest version 4.7.0.4 of the pop over plugin.

    /plugins/popover/inc/external/wpmu-lib/functions-wpmulib.php

    I can find the function _prepare_js_or_css in the following plugin file.

    /plugins/popover/inc/external/wpmu-lib/inc/class-thelib.php

    I have tested on my test site but didn't find any CSS file is changing on every site request.

    Could you please tell me specifically which CSS file is getting changed so that i can troubleshoot it?

    Regards,
    Vinod Dalvi

  • Jose

    Hi Alejandro,

    Hope you are doing great today,

    I was testing autoptimize plugin in my own environment and it is working fine. I don't get a new css file stored for each request.
    It would be helpful if you can share the content of the cache file that is being generated.
    Also If you can share the settings that you are using in autoptimize. There are not to many options, but I might be missing something. Maybe you are using some add-on for the plugin? Please advise.

    WPMU Popup pro is changing every request the css files (through the function _prepare_js_or_css in functions-wpmulib.php)

    The file that you are refering to was removed from the plugin in the version 1.1.0.
    Please make sure to not merge plugin files when updating. You should remove the current folder completely and reinstall a fresh version downloaded from our site.

    You know which is the problem, here is the guilty piece of code:

    That piece of code is called via an ajax request. It doesn't return a CSS file but a JSONP response, that's why I'm interested on seeing the generated file in your cache folder.
    JSONP is intended to not be cached by default. On each ajax request a random parameter is added to the query in order to avoid server side caching. That could likely be the problem if your cache plugin is misconfigured.

    Can you believe it?
    You are replacing the #messagebox for every line of the CSS for every request , applying the resource consuming function str_replace.
    This code is awful. Its slowing down my site, and is generating cache problems.

    I must disagree on this point. It is a very good code actually.
    PopUp plugin provides a huge amount of custom configuration parameters, displaying rules, dynamic content, etc. Most of those depends on dynamic and fresh data in order to work correctly.
    This specific block of code is necessary to support the templates feature. It will merge all the customization into the base template.
    str_replace is not resource consuming. It is in fact the most performant PHP method for text replacement. You might be confusing it with preg_replace maybe. If you run a benchmark over that routine, you will realize that it doesn't affect the performance of your site.

    Please let me know if you are still having issues after re-installing the plugin. I'm curious about what's going on on your site and I'll be glad to help to get to the bottom.

    Cheers!
    Jose

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.