YUI Compression? gui? and comptible with european letterS? - javascript

I am trying to find some sort of gui or batch utility where i can YUI compress a JS file i have.. I have a utility that sort of consolidates all my js into 1 single js .. and works great but i need to compress this file..
I was using something similar before to compress but it failed on european character i.e. character with accents over letters... like Día , Sábado etc
So basically what happend was it worked great but when i had a string with a european word with accents on it.. it would put escape characters in etc... I had to manually edit it.. it was a nightmare.-..
Can anyone point me in the right direction of a good GUI that works with YUI or somehtign similar so i can point it to my file (and files and i have more than one) so i can just one it like in batch mode or similar.. It needs to compress jquery also... i suppose yui has no issues with this?
Does anyone know if something like this exists at all?
I didn't really want to use the command like as i have a few files...
Any help really appreciated

My suggestion may not be exactly what you are looking for, but I am using batch file(s) to drive the compression/packaging of multiple JS files.
Without any special batch file fu, and assuming your on Windows, you could write a batch file similar to this (in the order in which you want the files to load in the browser):
compress.cmd:
echo. > compressed.js
java -jar yuicompressor-2.4.2.jar jquery.js >> compressed.js
java -jar yuicompressor-2.4.2.jar file1.js >> compressed.js
java -jar yuicompressor-2.4.2.jar file2.js >> compressed.js
You can then run this anytime you need to "re-package" everything into the single deployment file "compress.js".
BTW, make sure all your JavaScript source files are UTF8 and then run the compressor with the --charset UTF-8 option; this should take care of character encoding issues.

Related

Grunt Uglify weird characters at last line leading to no changes

I am working since month with Grunt Watch, which is using Uglify to minify Javascript files and also generating a .map file which worked perfectly since yesterday.
When I now do grunt watch and save a Javascript file, Grunt workes like intended and runs the tasks which copy the Javascript file into the public area and generating the filename.js and filename.js.map file into the public area.
Now I am refreshing the page to look my changes, but instead of my changes, the browser seems loading the old Javascript file (Yes, I am using version like filename.js?v=....).
When I look in the source code and open the Javascript file, at the end of the file following weird characters are there:
//# sourceMappingURL=filename.js.map��������������������
I am using Chrome as my browser and PHPStorm as my IDE.
I tried to convert to UTF-8, UTF-8 without BOM, changed line Feeds to LF and CRLF, but nothing seems to be the solution.
I also displayed all invisible characters to look if there is something hidden, but there is nothing.
Inside the generated file there is the console.log('Test'); I written into, but in the same file I opened in the source code, the console.log('Test'); is not there:
Open file in any IDE: [public/js/filename.js]
... function(){l=!0,console.log("Test"),c.setTimeout(fun ...
Open file in any Browser: [/js/filename.js]
... function(){l=!0,c.setTimeout(fun ...
If I delete the 2 files in the public folder, change something in the original file and save, grunt is uglifying and copying everything and it's working! But just this one time.. the next changes leading to the same weird characters and no changes to the file in the browser again.
Like I said: The whole process I am doing worked for months! But since yesterday it's not working anymore.
I didn't installed/patched anything. This behaviour came from one to another second.
Operating System is:
Linux packer-virtualbox-iso-14225xxxxx 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1 x86_
I am searching since yesterday, but can't find any solution or idea what is wrong.
Used to have the same problem. You should turn off your sendfile in nginx.
sendfile off;
see https://github.com/mitchellh/vagrant/issues/351#issuecomment-1339640
I just restartet my computer and it seems working right now.
But if anyone has a suggestion to prevent this or solving this problem in the future, I would be happy to hear from it! If in the next few days no answer comes, I will mark my answer as solution.

How to detect if a js file is minified at run time (Node.js)

I am using Node.js to minify javascript files and I would like to only minify the files that are obviously not minified already. I was wondering whether there is a way to find out if the file is minified through its content. I am using Node.js and filejs but I am up to any method as long as it is JavaScript.
Maybe you can try by checking how long the lines are, and how many spaces are used. Minified/packed JS typically has almost no spaces (typically in strings) and very long lines.
Also, i guess you can do one more thing(which can be automated by a script), parse through both the files and check for whitespaces and compare for them in both files. Usually, the one with lesser number of whitespaces will be the minified version. Also, use the ".min.js" namming. You can also compare the size of the files between normal js file and a minified js file(which will be smaller).
Get the first , say 50 characters, and check if there is any white space characters in it. Bit hacky but will probably do

tinymce build script to compress all js files

I am looking for a way to compress all tinymce js files into one single file.
I would like to use ant, yui-compressor and a build script. There seems to exist something like this already:
https://github.com/tinymce/tinymce
But i have not been able to make it work.
Can anybody with experience give me some assistance?
Solution from the tinymce forum (Spocke):
Install Java.
Install ant
Add ant to environment variable "path"
Open a console
cd to the tinymce dir and type "ant build_full"
We're using tinymce in our commercial grade productions. At first, we used their default .NET compressor. But, we've found it's too buggy for a real production. Then we made a simple IHttpHandler to concatenate given JavaScript files and JavaScript snippets. The handler also take advantages of caching to reduce response time. There should be some third party solutions if you don't want to waste your time.

Strange characters in Javascript causing it to not load

My site works fine on localhost, my javascript is loading and working fine. But when I deploy the site the script is not working. When I right click the page and say view source and then view the linked script file, it has some strange characters at the start of the file (function($){
On localhost, my script file starts like this (function($){
What is causing these characters to be prepended to my javascript file?
You have to re-save the file in encoding "UTF-8 without BOM".
You can use Notepad++ or other editors.
In visual studio:
By default, Visual Studio uses UTF encoding with the BOM; however, you can save it to a different encoding if you'd prefer. When you go to the Save As dialog, you can expand the Save button to see the 'Save with Encoding' option. This will prompt you for a different encoding, and I think one of the Unicode options will leave out the BOM (somewhere in the list is UTF-8 without signature).
Source: http://forums.silverlight.net/forums/t/144306.aspx
I think Briedis is right about the problem, but I suggest a different solution.
When you serve the file, is it being served with a Content-type like
Content-Type: text/javascript;charset=US-ASCII
?
If so, make sure to serve it with a charset of UTF-8 instead.
I just hit this same problem, and have found a fix.
As an answer to Martjin's question, the problem is that these URF-8 BOM characters invalidate the javascript when the client is expecting pure ASCII. So it will say there is an error at char 1, line 1 or some such, basically, right at the beginning of the file because it makes the codefile look like there's a typo in the first few bytes of the script.
In my case, I have a Site in IIS that is an ASP.NET app, and an Application underneath it that is also an ASP.NET app. This had caused some complications with inheriting web.configs, and the solution was to put a tag that negates inheritance from that point on.
I then discovered that all my .js in the child site was throwing an error for that stupid UTF-8 encoding symbol that was the first 3 bytes of every file. I am reasonably confident, that it is caused by some confusion in the httphandlers from my 2-tier solution for web.configs.
My solution, however was to convert the .js files back to pure ASCII, as that's what IIS was sending out and the client was expecting. For me, I have a build.bat that copies all the web files, removes any source control and project files and puts them all in a final build directory for copying to the test or production server. I made a modification to that script to also convert all the .js files to ASCII format.
It uses a combination of DOS batch (because that's where I started) and PowerShell (because that's the only way I found to convert without adding even more utility programs):
set DIRTOCONVERT=whatever path you want it to convert all the files for
ECHO remove UTF-8 BOM chars ï»? from front of files
for /r %DIRTOCONVERT% %%g in (*.js) do (
powershell -command "gc -en utf8 \"%%g\" | Out-File -en ascii .\tmp.txt"
move /y .\tmp.txt "%%g"
)
Note, a few people online (even in StackOverflow) had the idea to try:
type badfile.txt > goodfile.txt
but that still carries over the UTF-8 encoding. Apparently, it did not used to do that.
I had a similar issue, and found the fix when stumbling on this thread.
There was indeed a problem with the files not being UTF-8 (without BOM), but re-saving my js files as utf-8 didn't work, instead, it was my HTML file that imported these scripts that was the culprit. After I saved that file as UTF-8, the issue was resolved.

Compiling .hta file to .exe

I have searched far and wide for a way to compile my .hta file (and resources) to a .exe file.
There are plenty of applications that claim to be able to do this - but they have not worked for this application - which is a mixture of javascript and VB.
Simply, (and naively,) I don't want people looking at / screwing with the code. Any suggestions or solutions would be greatly appreciated.
EDIT: Of course, I understand that javascript and VB are not "compilable" since they are interpreted languages. I am just looking for a way to truly hide the source.
HTAEdit, which comes bundled with VBSedit, does not truly hide the hta code. At run time, it extracts the original hta file to a subdirectory in %temp% and passes it off to mshta.exe to execute. The converted exe's created by VBSedit don't seem to do this as far as I can tell.
Try using VBSedit, it definitely works for converting both vbs and hta to exe
You can "compile to exe" by simply wrapping the HTA into an executable which knows how to setup the HTA context/window.
The most trivial approach (which sounds like ExeScript) is to simply extract the HTA/resources first and then execute them. One could theoretically do this without temporary files by injecting data into a running IE context, but the task becomes more difficult. The internal JS may or may not be obfuscated and the wrapper may or may not add an additional layer of obfuscation/"encryption". (PayMo, and I am sure there are others, uses a wrapped context approach to distribute a single runnable exe).
If protecting "intellectual property" is the goal, hire a good lawyer :-)
I'm not sure about compiling to an exe - but if you minify & obfuscate your source code, unless you've got something incredibly valuable, it'd be a huge job to reverse-engineer.
http://developer.yahoo.com/yui/compressor/
Good luck.
You don't need a compiler, you need an encryptor/decryptor, like my project (under construction), the CFS project (Cryptographica File Security).
My clue is to create VBScript or JScript file for HTA to be dynamically spawned by. So you compile not HTA, but the script. This approach meets your security requirements much better than HTA packed to SFX.
Prepare the resources first - import to HTA all external files: scripts, stylesheets, and images (base64-encoded), to make your HTA standalone app. Then create eg VBScript file, and copy all HTML content from your HTA to the string variable in the script, replacing new line and tab symbols to " & vbCrLf & " and " & vbTab & ". Add code to create HTA window dynamically, .write() that string variable to the window's document, and quit script.
Note that Window_OnLoad() may not work properly due to pushing the content to window, that was already loaded.
Then just encrypt your completed VBScript to exe (using true encrypting utility, eg Primal Script 2012, ExeScript, VbsEdit or ScriptCryptor). And change icon with PE Explorer.
All that will take some time, but it is worth doing.
UPD: Here is an example of prepared script by the link.

Categories

Resources