Hello,
In some pages of Telerik site we can see large viewstate.
you can simply send viewstate to end of pages for faster download & better indexing in search engines.
My suggestion based on 2 posts from scott
1. Google AdSense and ASP.NET View State
2. Using a Base Class to Fiddle with a Page's Rendered Output
you can use this base class that the ASP.NET pages in your application extend for optimizing output of pages in your site.
using System.IO;
using System.Web.UI;
/// <summary>
/// Summary description for OptimizedBasePage
/// </summary>
public class OptimizedBasePage : Page
{
protected override void Render(HtmlTextWriter writer)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
int StartPoint;
int SLength;
//remove some invisible characters to compress output
html = html.Replace("\t", "");// tabs
html = html.Replace(" ", " ");// double spaces
html = html.Replace(" />", "/>");// space before end of tags
StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
if (StartPoint >= 0)
// does __VIEWSTATE exist?
{
SLength = html.IndexOf("/>", StartPoint) + 2 - StartPoint;
string ViewStateInput = html.Substring(StartPoint, SLength);
html = html.Remove(StartPoint, SLength);
int FormEndStart = html.IndexOf("</form>");
html = html.Insert(FormEndStart, ViewStateInput);
}
writer.Write(html);
}
}
Best regards
Mostafa
8 Answers, 1 is accepted
Hi Mostafa,
Thank you for your suggestion.
We're currently working on the optimization of telerik.com which includes optimization of T-SQL queries, cache, fast output of pages.
Best wishes,
Ivy
the telerik team
Thanks for reply & good news.
I want to reffer you to another link that make better performance for paging.
A More Efficient Method for Paging Through Large Result Sets
Best regards
Mostafa
Best wishes,
Ivy
the telerik team
Thanks for implement viewstate suggestion.
Best regards
Mostafa
I would like to implement the base class code you've suggested into my website (Built upon DNN) but I am afraid that I will crash some functionalities, specially that it is not me the main developer who developed the site, so I am afraid to ruin something by removing the ViewState hidden field value.
Please advise me.
Thanks
Hanan
you can make class like this:
using System.IO; |
using System.Web.UI; |
/// <summary> |
/// Summary description for OptimizedBasePage |
/// </summary> |
public partial class OptimizedBasePage : Page |
{ |
protected override void Render(HtmlTextWriter writer) |
{ |
StringWriter stringWriter = new StringWriter(); |
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); |
base.Render(htmlWriter); |
string html = stringWriter.ToString(); |
int StartPoint; |
int SLength; |
string ViewStateInput = ""; |
StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\""); |
if (StartPoint >= 0) |
// does __VIEWSTATE exist? |
{ |
SLength = html.IndexOf("/>", StartPoint) + 2 - StartPoint; |
ViewStateInput = html.Substring(StartPoint, SLength); |
htmlhtml = html.Remove(StartPoint, SLength); |
int FormEndStart = html.IndexOf("</form>"); |
htmlhtml = html.Insert(FormEndStart, ViewStateInput); |
} |
writer.Write(html); |
} |
} |
and use it.
Best regards
But you didn't asnwer my main question. Will removing the ViewState ruin any functionality that I don't know?
Also another question, isn't it affecting the performance to do this removing process before rendering the page?
Please advise.
Thanks
Hanan
I don't work with DNN. but i think DNN use same approch.
About performance:
We have a site with about 200,000 users and average 1100 online users and we use this solution to make better client rendering for pages but performance related to your server.
Best regards
Mostafa