Asp.Net OuputCache does effect JavaScript? - asp.net

I use Asp.net 4 c# and Page OutPut Cache IN MEMORY for optimizing performances.
For my understanding all the HTML generated by Server Controls will be cached for my page (in memory).
If in my Web Page I use references to CSS and JAVASCRIPT Files, example Google Adsense or others.
How Page OutPut Cache behaves?
Even my JAVASCRIPT will be cached?
Thanks for your time.

Page level, or output caching, caches the HTML output of dynamic requests to ASP.NET Web pages
With output caching, the final rendered HTML of the page is cached. When the same page is requested again, the control objects are not created, the page life cycle doesn't start, and none of your code executes. Instead, the cached HTML is served. Clearly, output caching gets the theoretical maximum performance increase, because all the overhead of your code is sidestepped.

Related

difference in performance between static html and asp.net site without dynamic controls.??

i use visual studio 2012 to make websites now since i like the IDE.I want to know that if there is any performance difference between a static html website and a website in asp.net without dynamic controls...
thanks.
Most of the time waiting for a web page to load is the network latency. Hardly any of it is latency due to the server dynamically generating the page (assuming the code isn't really bad). So the answer is, no, there is no noticeable difference to load time between static and dynamic pages.
Dynamic pages are mostly connected to a database server. So your app should query the database and fetch data, then manipulate the data and render as html page as output.
So html pages don’t need those steps therefore html pages are always faster than any dynamic pages (not only for asp.net but also other languages).

problem in load dynamic webpage (I want to indicate which part of my page load first in classic asp and also asp.net)

we are creating a custom content management and out portal page is bit bulky it is about 60Kb without images.
and during loading the page in some browser we can see some parts of site load faster than the other parts of the site where as we want to indicate (or instruct the web server) to load some of the areas first then load rest of the page.
is there any particulat setting in IIS for is there any particular method in classic asp for doing that?
also I have the same question in asp.net.
best regards.
I don't believe there is a built in way to describe which parts of a page load first in either ASP or ASP.Net. It really isn't a server decision - depends on how your browser parses the page and then requests the additional resources (or renders the existing ones).
You could potentially use AJAX and build in the order each section loads either as a state engine or by chaining. Seems to be pretty complicated for the benefit.
If you just don't want the user to see anything until the entire page loads you can control that from code using buffering. In classic ASP you use Response.Buffer and Response.Flush so the server doesn't start returning HTML until the whole page is ready - it will keep parts of the page from loading (the server won't stream results). I assume ASP.Net has a similar/identical method for buffering. Note that you can't pick sections of code with buffering but you can send only portions (top down) at a time.

How are .ascx files cached?

I have an asp.net project, and I load a base aspx page to display to the user. Then I ajax in the results of an ascx component and inject it via innerHTML in javascript.
I have noticed that the ascx component loads slowly on the first page load, but instantly thereafter. This is really cool, but I do not understand how this can be cached, as the contents are generated by making several db calls.
Does the server send some kind of hash to compare the contents to, to see if it changed on the server or not? Is this a browser thing or an asp.net thing?
What you are experiencing is most likely just in time compiling and has very little to do with the user control itself.
Watch the performance monitor counters for .net. This will tell you a lot about what's going on.
Can you use Firebug/IE developer console/etc. to determine the response code? If you can check the headers, you should be able to see a date that indicates either a cache time or a last modified date. I poked through the MS ASP.NET Ajax documentation, but couldn't find any references to default caching times or cache modification.
However, jQuery's ajax function uses an ifModified property which (according to the documentation) checks the Last-Modified header to determine whether or not it should retrieve the results. I'd imagine that the ASP.NET Ajax calls work in a similar fashion. It may not be prudent for your current project, but jQuery makes it very easy to set caching options.

What is faster and why?

For maintainability reasons, I want to database drive my javascript, in that I only want to send the javascript which is needed based on the users options.
So, is it faster/less resource heavy to have links in the database pointing to javascript files, then using response.writefile to embed those files into the clientside page, or is it faster/less resource heavy to stick the javascript script straight into the database, and response.write it onto the screen as and when needed?
So, is it faster/less resource heavy to have links in the database pointing to javascript files
Usually yes.
External Javascript files can be cached by the browser, and will be loaded only once. Javascript code injected into the HTML page needs to be loaded every time, which increases bandwidth and loading times.
Also, having JavaScript code in a static file (instead of a dynamic one that fetches the code from the database on every request) is bound to be the fastest and least resource-intensive solution.
Don't use Response.Write.
Be aware that if you send the entire JS file once, the client will / should cache it so it doesn't have to be sent again.
DB lookups for every page just to get the relevant JS will be slow.
By only sending the links to the javascript to the client a seperate HTTP request will have to be created in order to go and get each file.
If you embed only the required javascript directly into the page when needed this prevents this. Look at jQuery, thats got a load of javascript available to the client that isn't being used.
Less HTTP requests generally results in a faster website so I would go with embedding the code directly.
Edit:
I disagree with the caching answers above. If you ensure only the smallest amount of javascript that is required is embedded then my answer should be faster. This page will be cached too!

Generate static web pages from a template as part of ASP.NET Web application build

I'm building an HTML5 application (with ASP.NET back-end) and i want to develop it in such a way that i can run it locally with all my resources (such js and css) not minified (so i can debug it easily). However when i build the final version i want merge and minify the resources. At the same time i want to create several versions of the app targeting different platforms (iPhone, iPad, desktop, etc) by adding appropriate css.
I thought that the final output should be a set of html files (so the get cached nicely). I could use ASPX and just control the output by a query string parameter, but i don't really want to have the form tag on my page.
So the questions are:
What are the pros and cons of using static html pages generated from a template versus a dynamic ASPX page? (apart from being able to run on any web server)
If ASPX approach good enough then how can i get rid of the form tag that's required by ASP.NET?
UDPATE
Another factor in favor of static html pages is the fact that the files are served instantly, whereas ASPX may take awhile to load if the app has recycled.
The back-end is ASP.NET 2.0.
What are the pros and cons of using static html pages generated from a template versus a dynamic ASPX page? (apart from being able to run on any web server)
Pros:
Less overhead as you no longer have to serve ASP.NET pages through IIS
No viewstate, smaller page sizes (as long as your generator or build process removes them)
Faster loading times (due to the reasons above), though this could be achieved serving ASP.NET files with output caching.
Cons:
You obviously lose the ability to serve truly dynamic pages. This isn't a problem if you're not processing forms or have data that doesn't have to be updated often.
If ASPX approach good enough then how can i get rid of the form tag that's required by ASP.NET?
If you want to use WebForms and serve dynamic pages you can't get rid of it. If you're wondering how to get rid of it after the static html pages are generated, that could be done using an HTML parser simply enough during your build process.
I ended up using aspx pages. I removed form tag and it seemed to work (as long as i didn't use viewstate)

Resources