Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unminify / Decompress JavaScript

Original Question

This maybe a stupid question but is there a way in VS 2013 to unminify JavaScript?

Just making sure we are all on the same page here.

Minify:

var flashVer=-1;if(navigator.plugins!=null&&navigator.plugins.length>0){if(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]){var swVer2=navigator.plugins["Shockwave Flash 2.0"]?"

That's just an example to make sure we all know what I'm on about. As far as I can tell there is no way to be able to do this. I have only been using VS 2013 for around 3 weeks so there is probably still stuff that is hidden to me.

If there is no way to do this within the program what is the next best thing for this? I did see on another similar post that recommends the site http://jsbeautifier.org/ , so may have to give that ago but would make life easier if it was built into VS 2013

Thanks in advance as I know someone will be able to help me out here.


Update:

I have looked around VS 2013 and found nothing that can help me with this problem, like I said before they maybe some things I have missed (certain settings) so I guess if it cannot be done in VS what's the next best thing for the job? I seem to run into a fair amount of JS that is minifed and would like the quickest and best way to get the job done. I couple sites I have tried seem to have problems with it, is there a program I could install that would just allow me to short cut it with a hot-key or something. That would be pretty handy.


Update 2:

So I think its safe to say this cannot be done within VS2013, or for that matter at all due to missing var names and so on. So I have seen a few links and programs that allow you to format the code. Is there a way to do with within VS2013? And again if not what is the most reliable website/program that I can use to do this. Like I said I can see there have been answers and I appreciate all of them. I will be leaving this question open for a while to get more people to look at it and possibly give a better answer. Keep it up guys!


Update 3:

If anyone has any more information on this please do share. I am still looking around now and then waiting for someone to come up with something amazing for this. One day people.... One day!

like image 465
Ruddy Avatar asked Sep 26 '13 14:09

Ruddy


People also ask

Is there a way to Unminify JavaScript?

You can't unminify a minified file. There's no way to go back from this operation. You can use a beautifier to make it more readable, but you will have a weighty job of reverse engineering in order to understand what the code means.

Should you minify JavaScript?

It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.

How do I read a minified js file?

Open any web site. Open developer tools in chrome by pressing F12 /Ctrl + Shift + I/ right-click anywhere inside the web page and select Inspect/Inspect Element which will be mostly the last option. Go to Sources tab in developer tools and open any minified JS which you want to debug as shown in the image.

How do I Unminify JavaScript code in Visual Studio?

You cannot truly unminify javascript, as minified javascript replaces variable names with letters, as well as removing code comments - these cannot be "undone" as the original information no longer exists. It appears that you can at least recreate appropriate spacing, but "real" minified javascript cannot be undone.


1 Answers

The thing is that you cannot really "unminify" your code since some data was already lost - e.g. variable names. You can reformat it to more readable form though.

  1. According to this question, since VisualStudio 2012 you can just use Ctrl+E, D keyboard shortcut
  2. If the above is not right, there is this extension for VS 2010: http://visualstudiogallery.msdn.microsoft.com/41a0cc2f-eefd-4342-9fa9-3626855ca22a but I am not sure if it works with VS 2013
  3. There is an extension to VisualStudio called ReSharper which can reformat javascript in a few different manners.
  4. Also there are online formatters already mentioned in other answers (if your code is confidential, I would advise some paranoia manifested by downloading sources and using them locally).
  5. Also you may always try to find unminified version of desired library on the interwebs
  6. Also, there is the WebStorm IDE from JetBrains that is able to reformat JS - you may download a trial for the sole purpose of reformatting your minified scripts :)
  7. If that's just to make debugging easier, you may want to use source maps

Also, here is a bunch of related questions:

How to automatically indent source code? <-- this is for VS2010, but it looks promising, maybe it will help you if it supports JavaScript (and it does since VS2012 according to MS support):

Ctrl+E, D - Format whole doc
Ctrl+K, Ctrl+F - Format selection

reindent(reformat) minimized jquery/javascript file in visual studio

Visual Studio 2010 can't format complex JavaScript documents

Visual Studio code formatter

how to make visual studio javascript formatting work?

I am not sure if they figured out a working way to reformat JS, but I've seen a few answers which might be helpful - I am just pasting this in here just FYI.

Added 03.06.2014:

http://www.jsnice.org/

This tool could be useful too, it even tries to infer minified names. As stated on their website:

We will rename variables and parameters to names that we learn from thousands of open source projects.
like image 124
Adam Zielinski Avatar answered Oct 14 '22 15:10

Adam Zielinski