Support » Plugin: Autoptimize » Exclude JS Scripts not working correct?

  • Resolved mlfactory

    (@mlfactory)


    Hello,

    in my chase the exclude js file function not working correct.

    Exclude Scripts from Autoptimize: plugins/plugin-name/assets

    Also i tried plugins/plugin-name

    and i tried also plugins/plugin-name/assets/js

    Everytime in the Google Chrome Console:

    `http://foo.bar/wp-content/cache/autoptimize/js/lang/myscript.de.js?v=323 net::ERR_ABORTED 404 (Not Found)

    Script location is plugins/plugin-name/assets/js/lang/myscript.de.js

    What i am doing wrong?

    Many thanks,
    Michael

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    What i am doing wrong?

    nothing Michael, AO is doing it wrong in this case 🙂

    what happens:
    * you excluded a script
    * AO does exclude plugins/plugin-name/assets/js/language.js (or similar), but sees it is not minified (based on filename) and creates a minified version which is saved as wp-content/cache/autoptimize/js/autoptimize_single_xyz123.js
    * but lugins/plugin-name/assets/js/language.js tries to load myscript.de.js from the same directory but as the optimized script is in as wp-content/cache/autoptimize/js/, myscript.de.js cannot be found

    solution:
    * in AO24 use this code snippet;
    add_filter('autoptimize_filter_js_minify_excluded','__return_false');

    * in AO25 (in beta, can already be downloaded from https://github.com/futtta/autoptimize/archive/beta.zip I consider it pretty production-ready) you can simply disable the option to minify excluded files 🙂

    hope this helps,
    frank

    Hey Frank,

    many thanks 🙂

    Yes it works if i add
    add_filter('autoptimize_filter_js_minify_excluded','__return_false');

    And then i add manually the plugin path under “Exclude scripts from Autoptimize”

    But i like to do something like this:

    
    //Autoptimize fix
    if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
    						add_filter('autoptimize_filter_js_minify_excluded','__return_false');
    
    apply_filters( 'autoptimize_filter_js_minify_excluded', true, content_url()."/plugins/dsgvo-all-in-one-for-wp" );
    
    } 

    But sadly thos not working.

    Cheers, Michael

    • This reply was modified 2 months, 3 weeks ago by  mlfactory.
    • This reply was modified 2 months, 3 weeks ago by  mlfactory.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    well you could;

    -> minify all your own JS and rename the files into *-min.js or *.min.js in which case AO won’t re-minify
    -> use the following to exclude instead

    
    add_filter('autoptimize_filter_js_dontmove','add_dsgvo');
    function add_dsgvo($array_in) {
        $array_in[] = '/plugins/dsgvo-all-in-one-for-wp';
        return $array_in;
    }

    hope this helps 🙂

    frank

    You are the best 🙂
    Many many thanks and have a nice day/weekend,

    Cheers, Michael

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you’re welcome Michael, feel free to leave a review of the plugin and support here! 🙂

    Hello 🙂

    since a Update of your Plugin the code not working:

    		//Autoptimize fix
    		if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
    	
    			add_filter('autoptimize_filter_js_dontmove','add_dsgvo');
    			function add_dsgvo($array_in) {
    				$array_in[] = '/plugins/dsgvo-all-in-one-for-wp/';
    				return $array_in;
    			}						
    
    		} 

    Error:

    Refused to execute script from ‘http://domain.domain/wp-content/cache/autoptimize/js/lang/script.js

    Also the scripts loaded from cache….

    Why?

    Many thanks,
    Michael

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Can you try unticking the “Minify excluded CSS and JS files?”-option Michael?

    Ah ok that works.

    But… In my chase its a plugin… Now the Site Owner can’t use the “Minify excluded CSS and JS files” function, is that true?

    Cheers and Thanks,
    Michael

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    well, it’s new, added in Autoptimize 2.5 which was released earlier this week, so if the user hasn’t upgraded yet then that is true, but upgrading will “unlock” that feature 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.