Uploaded image for project: 'Tapestry 5'
  1. Tapestry 5
  2. TAP5-1541

Optimization load of scripts (javascripts and stylesheets)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 5.3, 5.2.4
    • 5.3
    • tapestry-core
    • None

    Description

      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.

          1. 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) {
      • return $A(collection).any(
        + contains : function(collection, assetURL) {
        + return 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 $A(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',

      Attachments

        1. tapestry-loadscripts-improvement.txt
          3 kB
          Pedro Ayala
        2. tapestry-loadscripts-improvement.txt
          3 kB
          Pedro Ayala

        Activity

          People

            hlship Howard Lewis Ship
            pjayala Pedro Ayala
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: