• Resolved CB

    (@cbrandt)


    Hello, friends at Advanced Ads!

    I would like to minify the output of Plain Text ads that contain HTML and some JS.

    It seems that the minify function available in cache and optimization plugins will not minify inlined JS to avoid breaking sites where the JS depend on line and character position to work. This is not the case with my ads. So I wonder if there’s some code snippet I could place on functions.php or some other way to get the ad minified before it’s passed on downstream as part of the page’s HTML.

    Thanks,
    CB

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support schmidt25

    (@schmidt25)

    Hi CB,

    Thanks for reaching out.

    Advanced Ads actually prevents plugins like Autoptimize from minifying the ad codes. Currently, there is no filter to change this behavior.

    To assess if we can change this in perspective, I would like to know which plugin you use for modification.

    Best regards,
    Joachim

    Thread Starter CB

    (@cbrandt)

    Hello Joaquim,

    Thank you for your fast response.

    I’m not using Autoptimize. I’m currently using the Clearfy plugin, but intend to migrate some of its optimization features to Litespeed Cache. So any solution involving either of these two plugins would help me.

    Best regards.

    Plugin Support schmidt25

    (@schmidt25)

    Hi CB,

    Thanks for this additional information. I forwarded it to Thomas and will keep you posted.

    Best regards,
    Joachim

    Plugin Support schmidt25

    (@schmidt25)

    Hi CB,

    We have problems replicating your issue. If testing several caching or optimization plugins, I notice that the JS modification doesn’t work at all, whether I insert the JS code directly or as an ad unit with Advanced Ads.

    I testes LiteSpeed as well as the Clearfy plugin (with the option Optimize JavaScript Code? enabled).

    In my first reply, I told you that Advanced Ads suppresses the minification of ad codes. This information was not correct. The plugin suppresses code optimization.

    Would it be possible to share the JS code from one of your ads?

    Best regards,
    Joachim

    Thread Starter CB

    (@cbrandt)

    Hello Joaquim,

    Yes, as I stated in my original post, these optimization plugins will not minify the code of inline JS in order to avoid breaking code that may potentially depend on line and/or character position to perform correctly.

    What I have been doing is I minify the code after I finish editing it, then insert the minified code in my AA ad. For instance, I have an ad that I use to place a widget, but the widget does not work on mobile. So the ad would be:

    [widget] // this shortcode opens the widget
    <!-- display: none // if user-agent contains string matching mobile's -->
    <script>
    	var mobile = /Mobile|Tablet|SmartPhone|iP(hone|od|ad)|Android|BlackBerry|IEMobile/i.test(navigator.userAgent);
    	if (mobile) {
    		document.getElementById("widget_not_on_mobile").style.display="none";
    	}
    </script>

    However, to avoid line breaks, spaces, comments etc on the final HTML, I minify this ad’s content before saving it on Advanced Ads:

    [widget]<script>var mobile=/Mobile|Tablet|SmartPhone|iP(hone|od|ad)|Android|BlackBerry|IEMobile/i.test(navigator.userAgent);mobile&&(document.getElementById("widget_not_on_mobile").style.display="none")</script>

    I have other ads that include much longer JS code, with several line breaks and comments, and I do the same to optimize them.

    It would be great if AA could optionally perform this minification whenever I save the Ad, so that the Ad itself remained more readable and editable, but the output would be sent pre-minified. After the ad is minified within AA, the optimization plugins will not interfere with that. They won’t minify, but they won’t revert an existing minification either.

    Thanks for taking the time to further try to help me.

    CB

    Plugin Support schmidt25

    (@schmidt25)

    Hi CB,

    Thanks for the explanation.

    I think the forum here is not the best place, and your suggestion would get lost here.

    I suggest that we close this ticket and I want kindly ask you to put this on our feature requests list, where all users can vote for certain ideas. This way, we can ensure that your idea doesn’t get lost.

    Best regards,
    Joachim

    Thread Starter CB

    (@cbrandt)

    Thank you. I’ll submit my suggestion there.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Need to minify ad with JS code in it.’ is closed to new replies.