Share via


Разгон страниц Sharepoint: жесткая оптимизация

????-?? ??? ?? ???????? ??????? ???????????? ??? ???? IHttpModule ? ??????? ???????? ? ????????? ??? ??????? sharepoint. ??????? ??? ??.

    /// <summary> /// ?????? ??????? ?????? ?? ???????? ????? /// </summary> public class OutputCleanupModule : IHttpModule { /// <summary> /// ????????????? /// </summary> /// <param name="app"></param> public void Init(HttpApplication app) { app.ReleaseRequestState += new EventHandler(InstallResponseFilter); } /// <summary> /// ????????????? ?????? ?????? /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InstallResponseFilter(object sender, EventArgs e) { HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; if ("text/html" == response.ContentType && true == request.Url.AbsolutePath.EndsWith(".aspx") && false == request.Url.AbsolutePath.Contains("_layouts/")) { SPWeb web = SPContext.Current.Web; if(false == web.DoesUserHavePermissions(SPBasePermissions.ManageLists)) response.Filter = new OutputCleanupFilter(response.Filter); } } /// <summary> /// ??????? ???????? /// </summary> public void Dispose() { } } /// <summary> /// ?????? ??????? ?????? ?? ???????? ????? /// </summary> public class OutputCleanupFilter : Stream { private static String[] completeTagsToCleanup = new String[] { "<meta name=\"GENERATOR\" content=\"Microsoft SharePoint\" />", "<input type=\"hidden\" name=\"__SPSCEditMenu\" id=\"__SPSCEditMenu\" value=\"true\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOWebPartPage_PostbackSource\" id=\"MSOWebPartPage_PostbackSource\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOTlPn_SelectedWpId\" id=\"MSOTlPn_SelectedWpId\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOTlPn_View\" id=\"MSOTlPn_View\" value=\"0\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOTlPn_ShowSettings\" id=\"MSOTlPn_ShowSettings\" value=\"False\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOGallery_SelectedLibrary\" id=\"MSOGallery_SelectedLibrary\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOGallery_FilterString\" id=\"MSOGallery_FilterString\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOTlPn_Button\" id=\"MSOTlPn_Button\" value=\"none\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOAuthoringConsole_FormContext\" id=\"MSOAuthoringConsole_FormContext\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOAC_EditDuringWorkflow\" id=\"MSOAC_EditDuringWorkflow\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOSPWebPartManager_DisplayModeName\" id=\"MSOSPWebPartManager_DisplayModeName\" value=\"Browse\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOWebPartPage_Shared\" id=\"MSOWebPartPage_Shared\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOLayout_LayoutChanges\" id=\"MSOLayout_LayoutChanges\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOLayout_InDesignMode\" id=\"MSOLayout_InDesignMode\" value=\"\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOSPWebPartManager_OldDisplayModeName\" id=\"MSOSPWebPartManager_OldDisplayModeName\" value=\"Browse\" />"+System.Environment.NewLine, "<input type=\"hidden\" name=\"MSOSPWebPartManager_StartWebPartEditingName\" id=\"MSOSPWebPartManager_StartWebPartEditingName\" value=\"false\" />"+System.Environment.NewLine, //"_spBodyOnLoadWrapper();", }; private static String[] tagsToCleanup = new String[] { "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1033/styles/core.css?rev=", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/Style%20Library/en-US/Core%20Styles/Band.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/Style%20Library/en-US/Core%20Styles/Controls.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1033/styles/HtmlEditorCustomStyles.css?rev=", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1033/styles/HtmlEditorTableFormats.css?rev=", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1049/styles/core.css?rev=", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/Style%20Library/ru-RU/Core%20Styles/Band.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/Style%20Library/ru-RU/Core%20Styles/Controls.css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1049/styles/HtmlEditorCustomStyles.css?rev=", "<link rel=\"stylesheet\" type=\"text/css\" href=\"/_layouts/1049/styles/HtmlEditorTableFormats.css?rev=", //"<input type=\"hidden\" name=\"__REQUESTDIGEST\" id=\"__REQUESTDIGEST\"", //"<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=", }; private static string[] scriptsToCleanup = new String[] { "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1033/core.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1033/init.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1033/ie55up.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1033/non_ie.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1049/core.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1049/init.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1049/ie55up.js?rev=", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/1049/non_ie.js?rev=", //"<script src=\"/WebResource.axd?", "<script> var MSOWebPartPageFormName = 'aspnetForm'", "<script type=\"text/javascript\" language=\"javascript\" src=\"/_layouts/portal.js?rev=", "<script type=\"text/javascript\">"+System.Environment.NewLine+"<!--"+System.Environment.NewLine+"var __wpmExportWarning", "<script type=\"text/JavaScript\" language=\"JavaScript\">"+System.Environment.NewLine+"<!--"+System.Environment.NewLine+"var L_Menu_BaseUrl", }; private Stream responseStream; private long position; public OutputCleanupFilter(Stream inputStream) { this.responseStream = inputStream; } public override void Write(Byte[] buffer, Int32 offset, Int32 count) { StringBuilder html = new StringBuilder(System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count)); foreach (String completeTagToClean in completeTagsToCleanup) { this.CleanUp(html, completeTagToClean, null); } foreach (String tagToClean in tagsToCleanup) { this.CleanUp(html, tagToClean, ">"); } foreach (String scriptToClean in scriptsToCleanup) { this.CleanUp(html, scriptToClean, "</script>"); } Byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(html.ToString()); responseStream.Write(data, 0, data.Length); } /// <summary> /// ???????? ???????? /// </summary> /// <param name="html"></param> /// <param name="search"></param> /// <param name="endTag"></param> private void CleanUp(StringBuilder html, String search, String endTag) { Int32 startPos = html.ToString().IndexOf(search, StringComparison.OrdinalIgnoreCase); if (-1 != startPos) { if (false == String.IsNullOrEmpty(endTag)) { Int32 endPos = html.ToString().IndexOf(endTag, startPos, StringComparison.OrdinalIgnoreCase); if (-1 != endPos) html.Remove(startPos, endPos - startPos + endTag.Length); } else { html.Remove(startPos, search.Length); } } }//**************************************************// Stream//************************************************** #region Stream public override bool CanRead { get { return true; } } public override bool CanSeek { get { return true; } } public override bool CanWrite { get { return true; } } public override void Close() { responseStream.Close(); } public override void Flush() { responseStream.Flush(); } public override long Length { get { return 0; } } public override long Position { get { return position; } set { position = value; } } public override long Seek(long offset, SeekOrigin origin) { return responseStream.Seek(offset, origin); } public override void SetLength(long length) { responseStream.SetLength(length); } public override int Read(byte[] buffer, int offset, int count) { return responseStream.Read(buffer, offset, count); } #endregion Stream }* This source code was highlighted with Source Code Highlighter.

?? ?????? ??????  ?????????. ?????? ?????? ??? ?? ??????????. ?????? ???? ?????? ? GAC ? ??????????? ?????? ? web.config

Comments

  • Anonymous
    January 01, 2003
    предыстория в том, что был полностью кастомизированный sharepoint. Со своими мастер страницами, стилями, страницами и т.д. Нужно было уменьшить вес страниц вырезав ненужные скрытие поля со страницы и чтобы стандартные css, js тоже не грузились

  • Anonymous
    June 19, 2009
    Тема интересная, для меня актуальная, но поскольку я не в курсе предыстории - непонятно: что вообще делает этот модуль и как его использовать? Жестко оптимизировать страницы очень бы хотелось...