Problem with option “Optimize HTML Code” and “Revolution Slider”
-
Hello,
In the Autoptimize plugin settings I am using option “Optimize HTML Code”. The only problem I have is with the “Revolution Slider” plugin output code, becuase after checking the code with https://validator.w3.org/ I get lot of errors like for example this one:
Error: No space between attributes. At line 220, column 18 ta-end="899400"style="z-index:Didn’t get similar errors when using other plugins or shortcodes with inline styles, etc..
Could you please help to correct it?
-
can you share your site’s URL wpuser10 (here or via futtta-at-gmail-dot-com)?
I tried to reproduce this myself but did not succeed in doing so, so I would need to see what is going on on your site @wpuser10.
To replicate please:
1) Install latest WP with for example “Twenty Sixteen” theme.
2) Install and activate latest version of Revolution Slider and Autoptimize.
3) Set the basic option “Optimize HTML Code?” in Autoptimize.
4) Import (Slider Revolution > Import Slider) for example this slider: http://revolution.themepunch.com/wp-content/uploads/2015/08/classicslider4.zip (it’s example from https://revolution.themepunch.com/free-slider-exchange/)
5) Create new page (Pages > Add new) and put this shortcode in text editor:[rev_slider alias="classicslider1"]
6) Test page using: https://validator.w3.org/ . You will see errors, like this:“No space between attributes.”
Hope this helps you to investigate and improve the plugin. Revolution Slider support suggested to contact you in this case. Please let me kow if you need more details. I was able to replicate this on different hosts. If you still couldn’t replicate then I could send you URL to check via e-mail (please let me know if still needed).
OK, I see what is happening; revslider is putting each attrib/value pair on a new line (don’t know why), and the HTML minifier AO uses keeps the linebreak but given the linebreak it considers it can safely remove the space.
Now As;
* revslider continues to work
* you could simply disable HTML optimizationI’m not considering this a priority issue, but if you want I could provide you with a code snippet that hooks into AO’s API to change the newlines into spaces?
frank
I’m not considering this a priority issue, but if you want I could provide you with a code snippet that hooks into AO’s API to change the newlines into spaces?
I see, yes, that would be great, becuase I don’t want to disable “Optimize HTML Code”, becuase this will affect the ranking in GTmetrix, etc.
It would be great to use your code snipped for now to quickfix it and it would be also great if this can be later implemented in the future release of Autoptimize, because Revolution Slider is very popular.-
This reply was modified 9 years, 7 months ago by
wpuser10.
OK, give this a try;
add_filter("autoptimize_html_after_minify","revslider_fixerupper"); function revslider_fixerupper($htmlin) { $htmlout=preg_replace('#\n(data-.*$)\n#Um'," $1 ",$htmlin); $htmlout=str_replace('"data-','" data-',$htmlout); return $htmlout; }frank
this one is better (more generic);
add_filter("autoptimize_html_after_minify","revslider_fixerupper"); function revslider_fixerupper($htmlin) { $htmlout=preg_replace('#\n(data-.*$)\n#Um'," $1 ",$htmlin); $htmlout=preg_replace('#(=\"[^"]*\")(\w)#','$1 $2',$htmlout); return $htmlout; }-
This reply was modified 9 years, 7 months ago by
Frank Goossens.
Thank you very much. I checked the first code and it didn’t work with my slider, but second code works very good, so that now I don’t have any errors from HTML5 validator. Finally I modified your code slightly to run it only if “Revolution Slider” and “Autoptimize” plugins are active:
if (class_exists('RevSlider') & is_plugin_active('autoptimize/autoptimize.php')) : add_filter("autoptimize_html_after_minify","crevslider_fixerupper"); function revslider_fixerupper($htmlin) { $htmlout=preg_replace('#\n(data-.*$)\n#Um'," $1 ",$htmlin); $htmlout=preg_replace('#(=\"[^"]*\")(\w)#','$1 $2',$htmlout); return $htmlout; } endif;Thank you!
great! 🙂
hey @wpuser10;
I just committed a fix for this in what will become AO 2.2. you can download the zip-file here and give this a try (overwritewp-content/plugins/autoptimizewith the contents ofautoptimize-masterin the zip)? looking forward to your feedback 🙂have a nice day!
frankHello,
I’m working with Slider Revolution and Autoptimize. Recently we got a 100/100 score in page speed but in testmysite.thinkwithgoogle.com we don’t score really well. So I did found the problem: in autoptimize the option “aggregate js html” is on. If I put this feature on off we score good in testmysite.thinkwithgoogle.com.
But then our slider won’t show. I already tried every combination in autoptimize, in slide settings (slider revolution) and global settings (slider revolution).
Also important to mention: whenever I put the right exclude in autoptimize our page speed goes down.Does someone know how to fix this problem?
Thanks in advance,
Daniel
-
This reply was modified 8 years, 10 months ago by
viet0viet.
will need some more info (i.e. your URL and what specifically changes in “testmysite” when “aggregate JS in HTML” is on vs off) @viet0viet ..
Thank you for your response.
This is the url: https://daizy.media
The problem is that testmysite.thinkwithgoogle.com doesn’t give any negative feedback. The report i get from google consists only green positive subjects.
This is the report: https://ibb.co/icr4UaWhenever i put the the aggregate js off. i get the exact same report (but only the speed in reduced) But my slider isn’t working then.
-
This reply was modified 8 years, 10 months ago by
viet0viet.
ah ok, the problem very likely is that you don’t have a page cache and that you have inline which changes frequently, which results in (a) the page being autoptimized every time (due to no page cache) and (b) autoptimize having to re-minify the JS time and time again which costs time and which makes your cache size grow fast.
solutions:
* disable “also aggregate inline JS” and exclude all of your slider JS from optimization (check your browser console for JS errors for guidance on what is going wrong)
* OR keep “also aggregate inline JS” active but exclude any inline JS that changes, e.g. the JS for the contact widget which you could exclude by addingtoAppend+=String.fromCharCodeto the comma-separated list of JS optimization exclusions.
* AND implement a page caching solution (e.g. a page caching plugin)groeten uit een regenachtig Brussel,
frankBeste Frank,
Ik maak gebruik van page caching (WP Fastest Cache). Als ik de optie ( aggregate js) uitzet krijg ik deze melding:
Failure at Presize of Slider:ReferenceError: jQuery is not defined
(index):491 Uncaught ReferenceError: jQuery is not defined
at (index):491
(index):542 Uncaught ReferenceError: jQuery is not defined
at (index):542
autoptimize_be16bac….js:8 JQMIGRATE: Migrate is installed, version 1.4.1-
This reply was modified 8 years, 10 months ago by
viet0viet.
-
This reply was modified 9 years, 7 months ago by
The topic ‘Problem with option “Optimize HTML Code” and “Revolution Slider”’ is closed to new replies.