[
https://issues.apache.org/jira/browse/TAP5-1541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044937#comment-13044937
]
Pedro Ayala commented on TAP5-1541:
-----------------------------------
Please ignore the first attachment, the second one add a simple optimization.
> Optimization load of scripts (javascripts and stylesheets)
> ----------------------------------------------------------
>
> Key: TAP5-1541
> URL: https://issues.apache.org/jira/browse/TAP5-1541
> Project: Tapestry 5
> Issue Type: Improvement
> Components: tapestry-core
> Affects Versions: 5.3, 5.2.4
> Reporter: Pedro Ayala
> Attachments: tapestry-loadscripts-improvement.txt,
> tapestry-loadscripts-improvement.txt
>
>
> While loading the script in the page, we are checking if the list of extra
> scripts are already included in the document.scripts or document.styleSheets.
> This process involves going through this documents scripts for each script we
> are loading, and since we are doing some processing each time the client side
> execution time it seriously affected.
> In order to reduce these process needed for each document script, we are
> creating a temporary array with the processed info, so we only need to do the
> check if the scripts are in this array.
> ### Eclipse Workspace Patch 1.0
> #P tapestry-core
> Index: src/main/resources/org/apache/tapestry5/tapestry.js
> ===================================================================
> --- src/main/resources/org/apache/tapestry5/tapestry.js (revision
> 1132663)
> +++ src/main/resources/org/apache/tapestry5/tapestry.js (working copy)
> @@ -2097,28 +2097,47 @@
> * elements) contains the given asset URL.
> *
> * @param collection
> - * @param prop
> - * property to check ('src' for script, 'href' to style).
> * @param assetURL
> * complete URL (i.e., with protocol, host and port) to the
> asset
> */
> - contains : function(collection, prop, assetURL) {
> + contains : function(collection, assetURL) {
> return $A(collection).any(
> function(element) {
> - var existing = element[prop];
>
> - if (!existing || existing.blank())
> - return false;
> -
> - var complete = Prototype.Browser.IE ?
> Tapestry
> - .rebuildURL(existing) :
> existing;
> -
> - return complete == assetURL;
> + return element == assetURL;
> +
> });
>
> return false;
> },
> +
> + /**
> + * Return collection with no blank elements
> + *
> + * @param collection
> + * @param prop
> + * property to check ('src' for script, 'href' to style).
> + */
> + getDocumentCollection : function(collection, prop) {
> + var documentScrips = [];
>
> + $A(collection).each(
> + function(element) {
> + var existing = element[prop]
> +
> + if (!existing || existing.blank())
> + return false;
> +
> + var complete = Prototype.Browser.IE ? Tapestry
> + .rebuildURL(existing) :
> existing;
> +
> + documentScrips.push(complete);
> + }
> + );
> +
> + return documentScrips;
> + },
> +
> /**
> * Add scripts, as needed, to the document, then waits for them all to
> load,
> * and finally, calls the callback function.
> @@ -2131,13 +2150,14 @@
> addScripts : function(scripts, callback) {
>
> var scriptsToLoad = [];
> +
> + var documentScrips =
> this.getDocumentCollection(document.scripts, "src");
>
> /* scripts may be null or undefined */
> (scripts || []).each(function(s) {
> var assetURL = Tapestry.rebuildURL(s);
>
> - if (Tapestry.ScriptManager.contains(document.scripts,
> "src",
> - assetURL))
> + if (Tapestry.ScriptManager.contains(documentScrips,
> assetURL))
> return;
>
> scriptsToLoad.push(assetURL);
> @@ -2167,13 +2187,14 @@
> return;
>
> var head = $$('head').first();
> +
> + var documentStyleSheets =
> this.getDocumentCollection(document.styleSheets, "href");
>
> $(stylesheets).each(
> function(s) {
> var assetURL =
> Tapestry.rebuildURL(s.href);
>
> - if
> (Tapestry.ScriptManager.contains(document.styleSheets,
> - 'href', assetURL))
> + if
> (Tapestry.ScriptManager.contains(documentStyleSheets, assetURL))
> return;
> var element = new Element('link', {
> type : 'text/css',
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira