How can I change jslint(VS 2010 extension) to ignore files? - asp.net-mvc

I have js lint installed in Vs 2010 as a extension through the extension manager.
It finds lots of errors but they are all from external plugins or from the jquery library. I am not going to go and fix stuff in an external plugin or jquery file. So how can I get it to not check these files?
I am also wondering how can I get it to ignore checking href links. I am using asp.net mvc so my links are like this
reg
So it can't find this path as it is the path to the controller action method not a file. So how can I get it to not look at these?
Thanks

You can exclude files (external plugins, jquery, etc.) from the JSLint validation process.
From here.
For the href issue, if you don't have any JS in your views, you could exclude those as well using the method above.

Related

Bundle Loading Scripts in wrong order

I am getting a jQuery is not defined error from jQuery validate being loaded before jquery.
I am not sure if this is involved with using ASP.net Boilerplate or not, though in the bundle config I have the following:
bundles.Add(
new ScriptBundle("~/Bundles/vendor/js/bottom")
.Include(
"~/lib/json2/json2.js",
"~/lib/jquery/dist/jquery.min.js",
"~/lib/bootstrap/dist/js/bootstrap.min.js",
"~/lib/moment/min/moment-with-locales.min.js",
"~/lib/jquery-validation/dist/jquery.validate.min.js",
"~/lib/blockUI/jquery.blockUI.js",
"~/lib/toastr/toastr.min.js",
"~/lib/sweetalert/dist/sweetalert.min.js",
"~/lib/spin.js/spin.min.js",
"~/lib/spin.js/jquery.spin.js",
"~/lib/bootstrap-select/dist/js/bootstrap-select.min.js",
"~/lib/jquery-slimscroll/jquery.slimscroll.min.js",
"~/lib/Waves/dist/waves.min.js",
"~/lib/push.js/push.min.js",
"~/Abp/Framework/scripts/abp.js",
"~/Abp/Framework/scripts/libs/abp.jquery.js",
"~/Abp/Framework/scripts/libs/abp.toastr.js",
"~/Abp/Framework/scripts/libs/abp.blockUI.js",
"~/Abp/Framework/scripts/libs/abp.spin.js",
"~/Abp/Framework/scripts/libs/abp.sweet-alert.js",
"~/lib/flatpickr/dist/flatpickr.min.js",
"~/js/admin.js",
"~/js/main.js",
"~/Scripts/jquery.signalR-2.2.3.js",
"~/Views/Shared/_Layout.js"
)
);
So I am using the minified version of jQuery and the minified version of jQuery.Validate. As soon as I use the minified version of jQuery and I load a page, jquery.validate.min.js is the first script that gets loaded in and as expected it throws a jQuery is not defined. error.
Though as soon as I do not use the minified version of jQuery (jquery.js) the scripts are loaded up in the correct order.
Is ASP.NET Boilerplate using any custom file ordering in the bundles that I do not know of? I do believe that MVC, but could be wrong, that it will process explicitly named scripts first in the bundle, then symbolically named scripts. Though these are all explicitly named scripts.
Is there something I am missing or some solution on how I can solve this?
I ended up using an answer from here: https://stackoverflow.com/a/11981271/4201348
So pretty much I defined my own BundleOrderer called AsIsBundleOrder that implementsIBundleOrderer that just returned the files as is, and set that as the orderer to use in the BundleConfig.
That works, though still doesn't give me a complete answer as to WHY (the important reason in my mind) the default orderer was only promoting jQuery validate to be before jQuery only when I used the minified version of jQuery.

TypeScript in MVC

Im bulding a website using MVC4. Recently I've read about TypeScript. It looks really nice however I cannot find any use for it in a MVC website. Am I missing something? Do you use it? Where?
TypeScript is a pre-compiler for JavaScript. Hence you can use TypeScript only as a replacement for JavaScript (server-side, e.g. Node.js, or client-side, i.e. in the browser).
As you are probably writing MVC4 code with C#, TypeScript will be of no use for you in relation to MVC4.
Regarding the client-side it's somewhat different.
I guess the main point you need to know is that TypeScript is not (yet) just another language on the server, that you can exchange with C#.
I find it quite useful for building largish apps with lots of logic on the client. The interfaces help avoid some errors. It compiles to javascript so you could use it instead of javascript. If you're just writing a couple of lines I wouldn't bother though.
You can link to the generated javascript files from TS files directly in the script bundles or HTML. If you want to automatically link to many JS files, use require JS. This will save you having to link to many js files.

Looking for an advise on bundling of JS

I have an MVC 4.5 project that has most of the UI logic organized in jQuery plugins. I want to protect my code by minification and bundling (While I understand that minification will only do so much as far as protection, it's better than leaving formatted and documented source files on the server.)
Ideally, I want my dev server to work as is -- files are non-minified and separated. But, when I deploy to the production server, I want the source files to be removed and only minified bundles to be available. Also note, on many occasions my jQuery plugins load other plugins from JavaScript code (I use head.js), so I cannot use #Script.Render for that.
What technologies do I use -- built-in MVC bundling, SquishIt, Bundler or do I need to resort to MSBuild and Microsoft Axaj Minifier? To recap, I want to remove source JS files and just be left with minified bundles in production, and, preferably, find a way to not change head.js references based on whether files are minified or not.
Thanks for your advice.
Just thought I respond with what I ended up doing here:
To recap: I wanted to obfuscate my source files with minification while not exposing the source JS files in production. I also wanted for head.js to resolve source file URLs to bundle URLs:
Put all non-minified javascript files in a folder viewable only to Admin role
Used bundling built-in to ASP.NET MVC 4.5 to generate bundles
Pointed my head.js tag to an MVC controller that returned head.js code + a javascript array with an x-ref between raw URLs and bundle URLs (available from BundleTable static object)
Bundling occurs outside of ASP.NET membership, so bundles are generated and available to anonymous users even though the source files are in the folder only accessible by Admin. Then, the trick of dynamically augmenting head.js code with server-side generated bundle URLs takes care of calling bundles from JS files.

How can i compile the js file in asp.net mvc or asp.net?

Is it possible to compile the js file in asp.net or asp.net mvc like to support server side variables for example globalization or any other variables?
You may take a look at RazorJs. It also has a NuGet package available.
Spark View Engine supports this and actually works very well for this.
It allows you to use ~/ in your resource files URLs and translates it to the site root.
http://sparkviewengine.com/
Otherwise you could just write a Controller action that parses (and maybe compresses) those resource files for you. This can be made easy by using something like Packer.

Correct Way to Code ASP.NET MVC HTML Helper That Requires an External JavaScript Library

I am getting ready to code a number of HTML helpers for UI elements in an ASP.NET MVC 3 project. I expect many of the helpers to depend on code that is located in external javascript libraries. These could be custom javascript libraries that I write, or they could reference 3rd party libraries like jQuery and jQueryUI. For example, I might write HTML.RichM.DataPicker(...) that would require the page to have jQuery and jQueryUI referenced and some code executed in the document ready function. Getting code into the document ready function is pretty straightforward I guess -- I could simply inject a new script block into the output with the contents of the function, even though that would mean I might have a page peppered with document ready functions all over.
The other part of this is making sure that the jQuery and jQuery UI libraries (in my example) are referenced and included. Is there an "MVC way" to add the code references to the view page or the layout/master if they are not already there, or must I instruct users of my HTML helpers that they need to add references manually for any required javascript files? Of course, I could just instruct them to include all possible external library references in the master or layout page, but that seems like overkill. In ASP.NET Web Forms, for example, I might have used RegisterClientStartupScript or RegisterStartupScript to do this from my custom control.
Thanks for any suggestions!
I think the easiest way is to include the dependant scripts in the header, that's maybe not what you want to do, but I think it's the easiest way.
I suggest you using a tool like SquishIt to bundle your JS files together, that way, you will not have to load like 20 js files, it will be more efficient and cleaner.

Resources