Best practice for SquishIt in develop time - squishit

SquishIt could bundle the js files. But I don't want to bundle it in the develop time. What is your best practice? There are some methods as below:
Add a global property to indicate develop time or production time.
use #if DEBUG ... #end
Above methods is not perfect, Is there any configuration switch on SquishIt for that?

If you have
<compilation debug="true">
<!-- snip! -->
</compilation>
in your web.config squishit should skip bundling and render individual file tags into your page.

Related

aspmvc - Script bundle on debug how to force reload

I have a ASP.NET MVC5 application and I have the following bundle:
bundles.Add(new ScriptBundle("~/bundles/appcomponents").Include(
"~/Scripts/js/jquery.min.js",
"~/Scripts/js/bootstrap.min.js",
"~/Scripts/js/modernizr.min.js",
"~/Scripts/js/detect.js",
"~/Scripts/js/fastclick.js",
"~/Scripts/js/jquery.slimscroll.js",
"~/Scripts/js/jquery.blockUI.js",
"~/Scripts/js/waves.js",
"~/Scripts/js/wow.min.js",
"~/Scripts/js/jquery.nicescroll.js",
"~/Scripts/js/jquery.scrollTo.min.js"));
When I'm in DEBUG mode I would like the browser to reload the scripts, actually I don't know if this already happens. If I set:
BundleTable.EnableOptimizations = true;
Then it works because I only get one dynamic reference, but in Developement (DEGUB) I don't get the dynamic parameter:
I was trying to do something like this but It didnt work:
Any clue? Or by default when you have bundle it doesn't matter if you are in DEBUG mode you always get the latest script?
By my understanding, you want to always get the newest scripts when in development (so no bundling and minification)
when you say debug, make sure your web.config should have compilation to debug="true", like below:
<system.web>
<compilation debug="true" />
<!-- Lines removed for clarity. -->
</system.web>
then bundling and minification should be turn off
if you set BundleTable.EnableOptimizations = true;, that means even when <compilation debug="true" />, bundling and minification will still function.
so you problem probably is because you are setting BundleTable.EnableOptimizations = true; which means you have activated bundling and minification all the time even in debug hence may be not getting the newest script
if bundling and minification is turn off but you still not seeing the newest script, it maybe browser is caching it, try load it in chrome incognito mode
more info about controlling bundling and minification, checkout official doc: https://learn.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification#controlling-bundling-and-minification

comment code in MVC5 web.config in debug mode

When I deployed my app I had to add following code to my web.config file because otherwise the server won't display my .svg file
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<system.webServer>
However, if I leave that bit of code in the file while I develop on my machine, it leads to weird errors (e.g., my machine doesn't load my .css file anymore). All works fine if I comment that out again while working locally.
But exactly that is a hastle, commenting/uncommenting that code always when developing resp. deploying.
So my two questions:
1) Is there a way to include code conditionally in the web.config, e.g., depending on if degug or release build, or if deploying?
2) Why is that code causing trouble on my local machine in the first place?
UPDATE: So Q1 is answered, but still looking for an answer to Q2! Can't accept an answer before that ...
In your web.config File you have an arrow that points to two other Files called Web.Release.config and Web.Debug.config there you can make such changes. There you can modify your web.config based on your Run Mode.
There is a very good Microsoft Article about it im pretty sure it will help you
https://msdn.microsoft.com/en-US/library/dd465326(VS.100).aspx

For Testing what to Write for constant name in struts.xml file

I am Using Struts 2 framework for my project, For Development mode i am using <constant name="struts.devMode" value="true" />
in struts.xml file, So my Development is completed so i need to give my project for Testing so what to change for constant name in Struts.xml for Testing (UIT), Its not in Production its in between Development and Production, please any have any idea
Well devMode is only there to make developer life easy by providing insight about the flow as well help you to reload your config of each request so that things can be smooth.
I believe that there is not going any changes on the QA and it do not make any sense to put dev mode there.
you have 2 options here
Comment out that line from your XML
If you are using any integration/build tool like Jenkins you can have property/conf file based on the profile

Visual Studio: How to override the default "Build Action" for certain extension types per project or solution?

I'm serving my asp.net mvc views from many assemblies and copying views to the main application on post-build event.
This works, however, I realized, that when I change something in view and just hit F5, changes are not included. What I have to do to see changes is to: save, build<- explicitly clicking, and then hit F5. However, it's pretty annoying solution.
I discovered that setting Build action to "Embedded Resource" on view solves the problem as well, however other devs may not remember that they have to do this after adding every view to the solution.
Is there a way to override the default build action for certain file extensions, such as: *.aspx, *.ascx in project or (better) in solution ?
What I've found is an ability to add this setting globally, per machine, but I do not want to do that (link: http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx)
Any ideas ?
Consider the following project file outline:
<Project ToolsVersion="3.5" DefaultTargets="EmbedViews;Build" ...>
...
<Target Name="EmbedViews">
<ItemGroup>
<EmbeddedResource Include="Views\*\*.aspx" />
<EmbeddedResource Include="Views\*\*.ascx" />
</ItemGroup>
</Target>
</Project>
This will add all aspx and ascx files in Views\<subfolder> to your library as Embedded Resource. Notice that EmbedViews is added to DefaultTargets before Build - order is important here, I found out making that mistake myself :-)
Since editing all your project files to get this snippet in is cumbersome, you could make your own project template with this included.
Please let me know if this helped.
In case anyone wonders here - there is still no way to do that if you want it to work on current and future items.
In VS 2017 when adding new file when the catch-all rule is present (e.g. Content Include = "**.*ts") if you add a new file, it will add it's own line to
<ItemGroup> with it's own BuildAction, ignoring your predefined catch-all.

Placing a web.config file in a view directory

I am having the standard issue timeout exception in my production environment whereby, after 90 seconds, the thread will be killed. For the vast majority of my site this isn't a problem.
However, my sitemap generator is an exception to the rule.
Because it relies on the routes created in the application, I have chosen to create it inside the project, as it loads all routes in from the app, and then, effectively uses a customised Html.Action to generate each route.
Because it takes a fair while to create the entire sitemap (5 minutes at last count), I get a YSOD before it has a chance to complete. Now, in webforms, I'd just create a web.config in the directory, and a nice little handler for that page using the location element:
<configuration>
<location path="sitemapgenerator">
<system.web>
<httpRuntime executionTimeout="600" /><!-- Ten minutes -->
</system.web>
</location>
</configuration>
Without actually creating this config file, I'm convinced that, not only will this not work, but it's also pretty bad practice in MVC anyway, because it then restricts the naming of the sitemap generator to whatever is set in the config file, and not just the routes.
I could just ensure that the routes and the config file stay up-to-date if I need to change it, but this just seems messy in MVC.
Can anyone give me any suggestions about this, and whether this web.config method will work out?
Many thanks in advance.
Update: I've done a test on this, and no, it does not work, so I have no fallback solution either. :)
Have you tried setting the scriptTimeout property in the initialization of the site map generator?
Server.ScriptTimeout = 600;

Resources