Is there a way to get a trace of what cshtml files are being used to construct a particular page load? For instance:
/Views/Shared/_LayoutUser.cshtml
/Views/Shared/_UserNavigation.cshtml
/Views/Shared/_BannerSelector.cshtml
RenderBody - /Views/Users/Index.cshtml
/Views/Users/DisplayTemplate/User.cshtml
Anything else used to construct view
/Views/Shared/_UserFooter.cshtml
Try Glimpse. It works much like Firebug does, except for MVC. It shows the execution tree of your views/partials/layout in a tree that looks pretty much the same as you described, including their execution times. It's very extensible as well, and there are plugins to trace Entity Framework, and JavaScript, etc.
Related
The 50 seconds it takes EF to complete it's first query (as compared to milliseconds for the same or similar queries when it's warm) is making my MVC website look bad. I really need to get pre-compiled views working.
I have tried the power tools but when I run 'Generate Views' the VS12 output window shows
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DbContextPackage.Utilities.EdmxUtility.GetMappingCollectionEF6(Assembly ef6Assembly, String& containerName)
at Microsoft.DbContextPackage.Handlers.OptimizeContextHandler.OptimizeEdmx(String inputPath)
The T4 templates that can generate views seem to be for code first only.
How can I get power tools working or is there another way to pre-generate the Views?
I have a habit of taking things to the extreme...
I also like the idea of wrapping structural sections of the site in custom semantic wrappers.
So when I started building web_ui components I ended up with something like this in my main entry page:
<x-container_fluid>
<x-header_fluid>
<x-site_header>
</x-site_header>
</x-header_fluid>
<x-old_browser>
</x-old_browser>
<x-home>
</x-home>
<x-footer_fluid>
<x-site_footer>
</x-site_footer>
</x-footer_fluid>
</x-container_fluid>
This works like a charm with the one exception being that on each page load the time lapse between 'Page Load' and 'Content Load' causes the browser to flash white until the controls render.
I 'think' my only option is to back off the dime a bit and move the structural bits back into the root page and instead add 'loading...' type placeholders anywhere there is a control that requires render/init cycles.
I'm wondering if there is any way (opt in?) to get the components to compile their templates into the hosting page at build time?
Any and all suggestions welcome!!
I'm wondering if there is any way (opt in?) to get the components to compile their templates into the hosting page at build time?
Not sure if this is going to give you exactly what you need but it is a very interesting lazy-loading technique that just may help:
http://googlecode.blogspot.co.uk/2009/09/gmail-for-mobile-html5-series-reducing.html
http://jsperf.com/stripoutcommentblock
Tom
in my project i have about 20 html forms with many different <input>'s. This <input>'s are unique in every form and they don't repeated between them. For each form there is a script which get data from form, generate specific file, and push it to the browser. and that's it. no databases, admin, logins/passwords and other usual web-app stuff.
so for example in php, project structure can be something like this:
forms/
------->form1/
--------------->index.html
--------------->script/
----------------------->index.php
------->form2/
--------------->index.html
--------------->script/
----------------------->index.php
and so on. It's quite clear and it makes pretty urls like:
www.website.com/forms/form1
but in Ruby-on-Rails there is a MVC pattern. And i have no idea how to organize structure with project like that. How to make it right? I should not to make 20 different controllers after all, right?
Yes you do make 20 controllers. In much the same way as you have 20 script/index.php files in your PHP structure. The rails structure would look something like this.
app/
controllers/
form1s_controller
form2s_controller
.....
formns_controller
view/
form1/
new.html.erb
form2/
new.html.erb
......
formn/
new.html.erb
layouts/
application.html.erb
Where the controllers have a method for each action that you want to perform e.g. new, edit etc
The layouts/application.html.erb file will contain all of the markup that is consistent across all of your pages.
Finally, don't try and fight the structure. It is there to enable minimal code because of convention, if you try and create your own structures you will create a world of pain.
Since there is no database backend for the forms, i would create one FormsController, with 20 methods (form1, form2, form3, ...).
Your urls would then look almost the same \forms\form1, \forms\form2 ...
Even if you would use 20 controllers, there are many ways in ruby to remove duplicate code. So even in a normal MVC, i have had applications with 140 models, and likewise as many controllers, most of these controllers had only one line and the views were completely generic.
Just because a certain solution seemed simple in PHP, it doesn't mean better solutions don't exist. Like for instance MVC. It might seem to induce more code, more files, more work, but the structure is there for good reason, it seperates the concerns cleanly, and each file in itself becomes more clear and easier to understand.
anybody knows which ones works faster ?
The Embedded Resources of the Input Builders are servered through the WebFormView engine. When your application is set to debug=false in your webconfig the view engine caches the view, so it is only loaded from the assembly once. The real reason why the input builders would be a little bit slower is that they use a master page to reduce the HTML you maintain. The Editor Templates will produce an input for example. The equvilent Input Builder will produce a label, input, and the html 'chrome" around the two so that you can specify it once and have it applied to every form that uses the input builder. The input builders are really for applying a convention for how your forms markup is built and it does it in a way that gives you control but also keeps your html fragments "DRY" (dont repeat yourself).
Like everything there are tradeoffs. For the input builders, you trade off some runtime performance for developer productivity. At the end of the day if you needed to have a super performant form on a public website, your best option would be to server a static html file that posts to an MVC Action.
Your answer depends on where you load your views pages from.
Templated Helpers have a slight edge because without any view overrides they are manipulating strings behind the scenes to produce html output.
Input Builders load views through embedded resources or through the traditional file system which will always be slightly slower than hardcoded string manipulation.
The code for both is similar and do basically do the same amount of reflection and metadata processing. Without any file or resource loading complications they both run at < 1 ms.
With customized template sourcing via embedded resources or file system calls your performance loss will be the same for both.
Recently I created a spike of a view engine, in which views are plain classes, and the content is created by using funny using-scope blocks.
The code together with a simple sample site is available at http://code.google.com/p/sharp-view-engine/
Here I'd like to hear your opinions regarding such an idea. Is it completely weird or maybe someone likes it?
I would actually not like that.
I can agree with DSLs (such as a Parser-Combinator or for generating XML Nodes in a data-context), but in this case I think that too much is being put in code that. And, in the end, this just complicates boundaries and leads to hard-to-maintain code. (You can already do the same, but with more verbosity just using the "standard" Web Controls. You can always use {subblock} in C# to limit a variables scope.)
The approach I prefer to use is templates with bindings (but no "code in templates"). That makes it easy for the "designer" (hopefully not me, or the next person to come along and) edit the layout of the view how they see fit. However, the core logic (the available controls and bindings) are kept in the code -- uncluttered. (Another advantage with the templates is that if they externally housed they do not require a recompile for every little change.)
Simplicity and maintainability are like ... zen.
This is an interesting idea taken to the extreme I'd say. At my shop we're using html conventions for pretty much everything except our layout. The only real html we have in the project is our Spark master page. For generating the content itself we use a convention engine that that spits out a semantic html model. (We're using the HtmlTags library from FubuMVC to build the semantic model.)
An example convention for rendering a multiline text box looks like:
public static HtmlTag Build(ElementRequest req)
{
return Tags.TextArea
.Rows(6)
.Id(req.ElementId)
.Attr("name", req.ElementId)
.Text(req.StringValue());
}
These conventions get triggered from reflecting on the view model (or we can manually call them from a helper method). The output is rendered (via ToString()) into the content section of our master page. We're joking that pretty soon we won't even need a view engine.
ps here's how we handle nesting. (Your using blocks look cluttered!)
return Tags.Div.Nest(
Tags.Button("save").AddClass("positive"),
Tags.Span.Text(" or "),
Tags.Anchor.Text("cancel").AddClass("negative")
);
Nest() is an extension method that simply takes a params array of HtmlTag and appends them to the parent's children collection.