Immánuel Fodor
Forum Replies Created
-
2.0.5 works like a boss on Windows even with messed-up encoding. Bravo! 🙂
Yes, I was lucky now as it contained English texts only. I posted it here only as a reference of what I did to solve my problem, it may help others.
If there would be a way to query PHP Minify why it returned an empty string eg. failed with wrong encoding, that could save us from a lot of trouble, you could use it for notification in the logs. Or if it returns empty for not empty input, then use this for indicating the encoding trouble. However, the ultimate solution is sanitizing the input before passing it to PHP Minify, then it can’t return empty.
I’ll definitely test any new solution if you push the 2.0.3 once! 🙂
Hi Raul,
I’ve checked the changes of 2.0.2 and downloaded the 3 modified files from the WP Trac:
https://plugins.trac.wordpress.org/changeset?old_path=%2Ffast-velocity-minify%2Ftags%2F2.0.1&old=1657113&new_path=%2Ffast-velocity-minify%2Ftags%2F2.0.2&new=1657113&sfp_email=&sfph_mail=The 2.0.2 update in itself didn’t help at first. Then I checked my theme’s js files in Notepad++ looking for character encoding other than UTF-8 as you suggested. Sadly, all files were utf8, but I converted the problematic plugins.js file to ANSI, just to try it out if any changes happen. KDiff3 instantly showed a couple of differences, eg. copyright symbols and weird whitespaces:
https://www.dropbox.com/s/pk1f9tlpt33idls/converted-to-ansi-copyright-and-other-characters.png?dl=0
https://www.dropbox.com/s/u8mv63jutgcm5n8/converted-to-ansi-weird-whitespace-characters.png?dl=0It was weird that it showed the weird characters in the utf8 file rather than in the ansi but at least showed that something is wrong somewhere.
I converted the file to different encodings and then back to utf8 but nothing ever helped, the weird characters always stayed there. Although Notepad++ showed as if there was nothing wrong, your plugin always left out the file. No comments showed up in the generated footer js file, PHP Minify just returned the usual empty string instead of=== false.Then I tried out several different utf8 fixer PHP libs but finally I went back to the basics, and stripped out every character from
x00toxFFother than alphanumeric, space, newline and other common symbols in the 7bit ASCII table.The quick&dirty stripper.php for the record:
<?php /** * Downgrading a file back to 7bit ASCII * @see: http://stackoverflow.com/questions/1176904/php-how-to-remove-all-non-printable-characters-in-a-string/1176923#1176923 * @see: http://www.bluesock.org/~willg/dev/ascii.html */ function revert_back_to_7bit_ascii($file) { $contents = file_get_contents($file); $fixed = preg_replace('/[\x00-\x08\x0b-\x1F\x7F-\xFF]/', ' ', $contents); // additionally keep \x09 the horizontal tab and \x0a the newline char file_put_contents($file, $fixed); } revert_back_to_7bit_ascii("plugins.js");If you remember, there were eg.
xC2characters as whitespaces in my js file, now there are none. Diff shows changes invisible to the eye but finally the special characters are replaced with spaces:
https://www.dropbox.com/s/061skc0edvcpb13/diff-to-before-and-after.png?dl=0After this conversion on my js file, your plugin runs smooth again on my localhost 🙂 and I have the 2.0.2 before anyone else 😀
Looking back, it could be seen as if I would tried to convert the plugin to my needs, however, my files needed to be converted to the plugin instead. Sorry if I took your valuable time.
For the record, I must add that it would be great to implement some sanitization to the input files before processing, like striping out these “broken” or “invisible” control characters, maybe it could achieve better compatibility for other people. I think, this was well done by my modification stripping the
h+andv+characters withumodifier, so I’d put it back to the code. I understand that you want to force theme/plugin devs to convert their files properly but there are many non-devs out there running their recipe blogs, etc. without knowing anything about their JS files’ encoding, and they just receive errors. If you still insist on no changes to the code, then I’d put some bold text into the plugin’s description, that if any error occurs and nothing seems to help, check the JS files’ character encoding as last solution.Thank you very much for your help, it was a really exciting Sunday investigating around here and there! 🙂
Cheers, Immánuel
Part 3, a further update to my previous comments
Changing the
!==operator solved getting theplugins.jscode into the footer js, however Chrome still gives an error and the JS is still broken. Now I get this:footer-57132dc5-1494758333.min.js:11922 Uncaught SyntaxError: Invalid or unexpected tokenClicking on the error shows veird <?> chars after the
uncode_progress_bar()function. I’ve opened the footer js in Notepad++, enabled theView->Show Symbol->Show All Charactersfunction, and this is what I can see, the first is my original file, the second is the processed footer js:https://www.dropbox.com/s/06k9ky5etkoaban/plugins-js-original-state-in-theme.png?dl=0
https://www.dropbox.com/s/gz2k5f0qmkt0djp/plugins-js-minified-state-in-footer-js.png?dl=0The line ending spaces became unicode
xC2(wtf) characters. Maybe this is why the PHP Minify library gives back empty string.
I echoed the JS before and after the# basic cleaning and minificationpart infastvelocity_min_get_js, and here is what I can see, before and after:https://www.dropbox.com/s/ttyctc3bz678rq3/plugins-js-before-basic-minification.png?dl=0
https://www.dropbox.com/s/9v63iaum1jjvo1h/plugins-js-after-basic-minification.png?dl=0Before the basic minification there are spaces and after it there are unknown characters. So I went for what the
\hand\vmodifiers mean in thepreg_replacecalls, maybe these are not working well, only those had the+quantifier which left out the BOM replacing. I’ve seen here http://php.net/manual/en/regexp.reference.escape.php that these are horizontal and vertical whitespace characters, and bumped into the first sentence of this page as well: http://php.net/manual/en/regexp.reference.unicode.php“three additional escape sequences to match generic character types are available when UTF-8 mode is selected”
Unicode mode? Hmmm, sounds interesting as I have unicode character errors. The unicode mode can be selected with the
ucontrol character according to this page: http://php.net/manual/en/reference.pcre.pattern.modifiers.php
I replaced your original regex patterns from'/\v+/'and'/\h+/'to'/\v+/u'and'/\h+/u'… and … there are no console log errors and my theme doesn’t get tangled on the frontend by the missing/invalid plugins even when I use the original js files of my theme not the inbuilt minified versions! 🙂JS output right after the modified replaces:
https://www.dropbox.com/s/d4k75jdpq634n3p/plugins-js-after-basic-minification-with-unicode-replaces.png?dl=0
The final footer js with the plugins.js code minified. It seems that even PHP Minify was able to run after the proper unicode repalcement, which is a big win:
https://www.dropbox.com/s/00yx91b9tiifq0e/plugins-js-after-the-mods-in-footer-js.png?dl=0Congratulations if you made this far with reading 😀
To sum up my debug session, what I suggest to modify in the 2.0.2 version:1. Replace the
if($min !== false) { return $min; }
line to be
if($min != false) { return $min; }
or
if(!empty($min)) { return $min; }
in the end offastvelocity_min_minify_js_stringfuntcion to do not exclude the file contents if PHP Minify fail with returning notfalsebut empty string.2. Replace the
$js = trim(join("\n", array_map("trim", explode("\n", preg_replace('/\v+/', "\n", preg_replace('/\h+/', " ", $js)))))); # BASIC MINIFICATION
line to be
$js = trim(join("\n", array_map("trim", explode("\n", preg_replace('/\v+/u', "\n", preg_replace('/\h+/u', " ", $js)))))); # BASIC MINIFICATION
in thefastvelocity_min_get_jsfunction to enable UTF-8 mode for thepreg_replacefunctions for safe character replacement in uft-8 files.
This one is the most important mod as it enables PHP Minify to run by eliminating the broken unicode characters which causes empty string to return.Now, the plugin works like a charm on my Windows 10 laptop, this should be enough for basic Windows support 😉
Cheers,
ImmánuelPart 2, an update to my previous comment
I’ve debugged the plugins code, here is what I’ve found.
Thefvm_download_and_cachefunction is able to open the files on Windows as thefile_get_contents($f)inside theif (stripos($hurl, $wp_domain) !== false)andif (file_exists($f)) {returns all the files’ contents properly, no prblem about the different slashes. Theplugins.jsis also there if I echo its contents.
The problem is that thefastvelocity_min_get_jsfunction returns only a;after processing myplugins.jsfile. Inside it the.min.jssuffixes get excluded, this is how myplugins.min.jsis being copied well to thefooter.js, as it is not runned through the minification.
Inside the function, the js code is also present after running through the# basic cleaning and minificationpart but it is empty string after thefastvelocity_min_minify_js_stringcall.
Inside it, I’ve found that my code disappears after the$minifier->minify()call, it returns empty string, from a var_dump:string(0) "". As you examine theif($min !== false),minis notfalseby type, butfalseby “value”. Replacing the!==with!=solves the problem. I think it is more elegant to use theempty()function there instead of a logical expression:
http://php.net/manual/en/function.empty.php
For my footer js, here are the expressions evaluations where thefastvelocity_min_minify_js_stringis called (from echos in the function):D:\work\immanuel60.hu\trunk\web/wp-includes/js/underscore.min.js D:\work\immanuel60.hu\trunk\web/wp-content/plugins/uncode-daves-wordpress-live-search/js/daves-wordpress-live-search.js (min !== false) - bool(true) (min != false) - bool(true) (!empty(min)) - bool(true) D:\work\immanuel60.hu\trunk\web/wp-content/plugins/i-recommend-this/js/dot_irecommendthis.js (min !== false) - bool(true) (min != false) - bool(true) (!empty(min)) - bool(true) D:\work\immanuel60.hu\trunk\web/wp-includes/js/mediaelement/mediaelement-and-player.min.js D:\work\immanuel60.hu\trunk\web/wp-includes/js/mediaelement/wp-mediaelement.min.js D:\work\immanuel60.hu\trunk\web/wp-content/themes/uncode/library/js/plugins.js (min !== false) - bool(true) (min != false) - bool(false) !!! it would return the js instead of the "minified empty string" (!empty(min)) - bool(false) !!! it would return the js instead of the "minified empty string" D:\work\immanuel60.hu\trunk\web/wp-content/themes/uncode/library/js/app.js (min !== false) - bool(true) (min != false) - bool(true) (!empty(min)) - bool(true) D:\work\immanuel60.hu\trunk\web/wp-includes/js/wp-embed.min.jsIn my opinion, please consider modifying that
ifstatement in the next release (eg. 2.0.2).Part 1
Wuhuu, I’ve made it work on Windows, too! 🙂
The solution for me was to turn my theme’s production mode ON, which includes the minified version of all its scripts, so your plugin leaves them out from processing. The changed line from the new logs:- FILE - /wp-content/themes/uncode/library/js/min/plugins.min.js --- Debug: File was opened from D:\work\immanuel60.hu\trunk\web/wp-content/themes/uncode/library/js/min/plugins.min.js ---The theme’s included files in production mode have a
.minsuffix, so your plugin doesn’t re-minify them, just copies its contents into the footer JS. And this is what I need to make it work! 🙂If your think, your can close the ticket or leave it open until you find a proper Windows solution. Now I think the problem is somewhere around the minifying process.
I’ve written a long reply, it doesn’t show up here, what is happening with the support forum!? 😀
I can confirm that on the live site everything is working properly with 2.0.1 as it is running on a Linux server.
However, I’m sorry for those who are on Windows hosting and for my localhost, too. I need to find some solution for this, maybe some code in myfunctions.phpto turn off your plugin on localhost, or disable only the JS processing.
What I still don’t get is how all the files are being compiled into the footer JS while leaving out only one file. If it is not supposed to work on Windows, how the other files are processed fine, what is the difference with this particular one.Hi Raul,
Thanks for your reply, I did the analysis on my site as you’ve suggested.
Basically, everything is in the same order, no change at first sight in the process order. Then I took a look on the generated files. Hashes are the same in the generated JS and CSS filenames, only the time stamps are different. Then I moved on and looked through the distinct files one by one, and diffed the changes of the 1.5.3 and 2.0.1 generated files. I used the source control’s diff, which highlighted the changes in each file pairs. Only minor changes can be found in all but in my case, thefooter-57132dc5js is completely different. The main difference is that a whole js file is missing! :O I think this causes my site’s disintegration. The missing file is the one ending withlibrary/js/plugins.js, you can find in the logs. This is a plugin file for my theme and thelibrary/js/app.jsdepends on it. The first console log error also proves this concept:footer-57132dc5-1494694436.min.js:52 Uncaught TypeError: $(...).tooltip is not a function at Object.UNCODE.utils (footer-57132dc5-1494694436.min.js:52) at Object.UNCODE.init (footer-57132dc5-1494694436.min.js:296) at footer-57132dc5-1494694436.min.js:297 at footer-57132dc5-1494694436.min.js:297The error is in the 52nd line, and in the 1.5.3 the plugin.js file’s content were before it, so it is obvious to break now. You can access the js/css files on the live site according to the logs, if you need them for examination.
I’ve attached both cache outputs in the below zip, you can see the differences in the files, too.
https://www.dropbox.com/s/sb4a0zu4v9w9e49/immanuel60.hu.fvm.cache.zip?dl=0
I hope this information can help you solve the issue.Cheers,
Immánuelps. My dev/staging machine is a Windows 10 computer with WAMP installed, HTTPS enabled on localhost, and the virtual server’s name is the same as my live site. In this way, I can use the SSL certs of my live site on localhost and DB migrations are also easy as no need to change any domain names from live to local and vice versa. Changing between the two is done with a clever windows .bat file, so I can remove or add the domain to my Windows’ hosts file wit a double click to route any requests to my laptop, or let it go to the net. I always have Chrome dev toolbar open with Disable Cache enabled. I’ve added this note in case you would be curious how the live domain is in the logs, however it comes from localhost. But I think there is no correlation between my setup or the broken js, the missing file should be there using any machine.
Just for curiosity, I reverted your plugin’s source code changes in version control from 2.0.1 to 1.5.3, purged the cache, and everything works fine on localhost. No changes on admin while doing the revert, the original settings was there which produces broken JS on 2.0.1. Hence, I’m pretty sure that some code changes of the plugin made the JS broke. You write in the changelog that it was modified for “better compatibility”, however, my site seems to be preferring the “advanced” approach, rather than compatibility 😀
Forum: Plugins
In reply to: [Widget Instance] [SOLVED] No widgets in the dropdownVery kind of you, thanks! 🙂