Grunt Uglify weird characters at last line leading to no changes - javascript

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.

Related

How can I effectively edit jupyter notebook's javascript files?

So notebook's js files are all stored in python_packages_folder/notebook/static/notebook/js however when I edit them, no change happens and checking the loaded js files on the browser I find them look like as if they were not edited. Why does this happen?
I had the same problem when I want to temporarily test some use cases. I hacked it by doing the following:
cd python_packages_folder/notebook/static/notebook/js
mv main.min.js main.min.js.bak
cp main.js min.min.js
Then you restart your jupyter and open one notebook you will see all the original (not-minified) javascript files. They all come with an ?v=timestamp suffix, indicating they will be reloaded when you modify them.

After save (ctrl+s) Javascript file change all format

I am having a problem with intellij IDE community edition 14.03 version that i hope you can help me,
when i modify a javascript file (an small change like a space) looks like intellij is changing the format or something behind scenes because when i check with svn tortoise in show differences as unified diff option looks like i was changing all my file, removing all the lines and the adding them again with the new change(the space that i added).
note: i was modifying the same file with webstorm IDE and when i select the same option(show differences as unified diff), this is just modifying the line that i change. i dont know if is something in my setting or a bug.
after checking this problenm with intellij team, in the bug
https://youtrack.jetbrains.com/issue/WEB-15304
We realize that the problem was due to .editorconfig file, we can work with .editconfig file to standarize the format of our files, doesn't matter what IDE are you working on, but in my case this file was getting my a headache, in my case the only thing that i need to do to solve my problem was remove does files in my project and everything is working fine now.
but i just wanna to mention that this file could solve a lot of our problems if our team work with differents IDEs
I am leaving the link about this if you are interested on it.
http://editorconfig.org/

original vimrc file. Where to fnd? how to restore?

I was trying to set up vim to work with JavaScript (any links about that appreciated), though didn't even know what's .vimrc file. So I deleted it. After removing and installing vim for about 10 times... I now don't know what exactly should I do. I believe there was some default settings that I lost. If I google for it I find bunch of different vimrc files, and if I put their content in my vimrc - whenever I start vim I get a lot of errors (assuming because I don't have all the plug ins). also don't think that I should\can create one and fill it little by little.
so.
1. How do I restore my original vim state (if you think this is smtn I should do) - ?
2. How do I set it up to work nicely with JavaScript files?
3. Possibly good vim tutorial?
OS Ubuntu 12.04 32-bit
Thank you guys.
vim beginner.
If you hadn't customised the file at all before you started, then if it existed at all, it must have been the default for new users.
When creating a new user account, the files in /etc/skel are used to populate the new user's home directory; thus the file you deleted can probably be restored to its original state with the following command:
cp /etc/skel/.vimrc ~/.vimrc
That is "copy the .vimrc file from the skeleton directory into my home directory".
If that doesn't help, or if the file you deleted was actually the system-wide defaults (normally /etc/vimrc or /etc/vim/vimrc) then you can probably get hold of the original file from your OS's package archive.
Since you are running Ubuntu 12.04, the relevant file list seems to be this one: http://packages.ubuntu.com/precise/i386/vim-common/filelist It doesn't seem to put anything into /etc/skel, but it does install an /etc/vim/vimrc which includes /usr/share/vim/vimcurrent/debian.vim.
You can download the package manually from here - the .deb file is just a .tar.gz, so tar -xzvf foo.deb will extract it for you to poke around. cd to a new empty directory before doing that, or you'll get very confused by the directories it creates!
Another thing to double check is that Ubuntu actually has multiple different vim packages, e.g. vim-tiny. See this question for how to check you've installed and selected the "full" version.
A .vimrc file is optional, and without it vim will use all of its defaults.
These defaults, however, are a bit conservative. If I recall correctly, vim defaults to being compatible with its predecessor (vi), which means no syntax highlighting, no line numbers, no ruler to tell you which mode you're in, no nothing.
Tim Pope's sensible vimrc is a good point to start off.
.vimrc usually is a config file under your $HOME directory. Itself is a vimscript too. You can put your config/mapping/plugin config/function... there, so that everytime you started your vim, the file would be automatically loaded. then you have a customized comfortable editor opened.
without this .vimrc, vim can start too, with default config though.
you can start vim and type :h vimrc to see the help doc of vimrc. You can take a vimrc from internet, try to understand the settings in the file. finally make your own vimrc. It will take veryveryvery long time to have a satisifed vimrc. I have used vim for about 10 years, last week I was still editing my vimrc file.
When you read others' vimrc settings, use :h foo to find the help information. In this way, you know "why I set this", not "I don't know what's going on, just copied it".
The charm of vim is, it is highly customizable. You can change it into plain notepad or programming IDE or mp3 player...
enjoy editing!

Why do some PHP or JS files get uploaded as one-line rather than keep formatting?

I am offering zip files of a plugin I wrote with JS, PHP and CSS files for the user to upload to their server. However, in some user cases the JS file gets uploaded as one line, obviously causing a massive FAIL and a complaint from users. To get it working again, I just open the file and copy/paste from my properly formatted version onto theirs. Presto! So, can someone explain what is going wrong here and how I can prevent this easy-to-fix but time consuming problem? I am using Notepad++ on Win, is there some kind of setting I should be using to save my files? Or is it a remote server problem that I just can't prevent?
Most likely this is caused by different line endings and their interpretations on various operating systems. I would thought that nowadays these problems are over, apparently not.
Ask your customer for any file created on the target system and see what line ending is natively used there. Then simply give them file for the target platform (AFAIR Notepadd++ allows you to save file in with any EOL).

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.

Categories

Resources