Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collect useful JavaScript exceptions when using a minifier?

I'm a big fan of Exception Driven Development. Because the big amount of client-side JavaScript in modern day applications, this means we also collect JavaScript exceptions by sending them to the server.

But as far as I can think of this excludes the use of a minifier? It destroys all the useful information by showing errors like:

k is undefined, line 2 column 23489 in function l()

Are there any workarounds for that?

More info Maybe one option would be to create a metadata file at the moment you're minimizing. When this meta data lives on the server, it can remap the minimized error to the original variables and linenumbers with the metadata. Sounds like a lot of work though.

like image 391
Dirk Boer Avatar asked Nov 07 '14 07:11

Dirk Boer


People also ask

How do I minify a JavaScript file?

To minify JavaScript, try UglifyJS. The Closure Compiler is also very effective. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.

Should I minify JS?

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.

Why do we need to minify JavaScript?

Minification is the process of minimizing code and markup in your web pages and script files. It's one of the main methods used to reduce load times and bandwidth usage on websites. Minification dramatically improves site speed and accessibility, directly translating into a better user experience.

How do I minify a file?

Download the files that you want to minify from your website. Save a copy as a backup. Copy the content of the file and paste it to the appropriate minifier tool. Once it's done, paste the code back into the downloaded file and upload it to your website directory.


1 Answers

You can use Javascript source maps after minification to check where the error actually is (and this supports your idea of metafiles).

Hope this article will help you and I understood you right. http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

like image 101
euvl Avatar answered Jan 02 '23 06:01

euvl