Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions
Author Message
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Wed Feb 11, 2009 8:25 pm Reply with quote

I'm sure you are already under way and/or thought about it, but if not there is a defiant need for an optimised way of adding js and other files to the core.

e.g. someway we can add a js script file without having to edit the core manually.

Code:



add_rn_js('head', 'includes/myjavascript.js');
add_rn_js('body', 'includes/myjavascript.js');



I guess I mean on a per module basis.so the first example would add js to the header and the second to the body.The function or method used could also have xss checking as well maybe.

RN should have done this already, I mean state one thing you lazy buggers have done lately apart from optimizing and releasing a new version as well as working on the update Razz
 
View user's profile Send private message
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Feb 11, 2009 8:42 pm Reply with quote

We have an issue open on this and i would expect it to be included in the next release after 2.30.01.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
testy1







PostPosted: Wed Feb 11, 2009 11:54 pm Reply with quote

ok thanks....
 
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Thu Feb 12, 2009 6:04 am Reply with quote

glad to see this made it from the "lust factors" Smile

Support for adding multiple scripts would be a plus... Some scripts need to run at the end of the page right before the closing body tag, so maybe options for adding to footer too?

Code:
add_rn_js('head1', 'includes/myjavascript.js');

add_rn_js('head2', 'includes/myjavascript2.js');
add_rn_js('footer1', 'includes/myjavascript.js');
add_rn_js('footer2', 'includes/myjavascript2.js');


maybe thats what you meant by "body"...
 
View user's profile Send private message Visit poster's website
testy1







PostPosted: Thu Feb 12, 2009 6:44 am Reply with quote

I thought i had posted about this but couldn't find it Sad

and yes footer is a good idea.
 
Palbin







PostPosted: Thu Feb 12, 2009 3:10 pm Reply with quote

What would be the benefit of adding javascript into the body or the footer? Why not just add it into the head?
 
testy1







PostPosted: Thu Feb 12, 2009 4:03 pm Reply with quote

because sometimes it needs everything to load before it executes....like analytics for example
 
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Feb 13, 2009 5:45 am Reply with quote

testy1 wrote:
because sometimes it needs everything to load before it executes....like analytics for example

Yes or some other js that relies on parsing the page after it has loaded, for example doing nifty tricks based on CSS attributes
 
View user's profile Send private message Send e-mail
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Feb 13, 2009 7:03 am Reply with quote

Or, one could/should use onload events or event handlers to kick off such processing... no real need to put JS at the end IMO. But, just a personal preference is all, and, yes, it is extra work.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
spasticdonkey







PostPosted: Thu May 28, 2009 7:49 am Reply with quote

Well I was playing around with ySlow last night, which for those who arent familiar, it will tell you way more than you ever wanted to know about optimizing your page(s)....

Noticed on one of my pages that it had 9 external JS files, and 5 CSS. Sad
That's alot of http requests... Ever any thought of implementing something like this in RN?
[ Only registered users can see links on this board! Get registered or login! ]

It basically combines js and css files and caches the result. Next time that combination of JS/CSS is needed it can access again. Going from multiple http requests to 1, sounds like a good idea to me Smile
 
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6433

PostPosted: Thu May 28, 2009 10:37 am Reply with quote

You mean something like this?

_________________
I search, therefore I exist...
nukeSEO - nukeFEED - nukePIE - nukeSPAM - nukeWYSIWYG
 
View user's profile Send private message
spasticdonkey







PostPosted: Thu May 28, 2009 11:20 am Reply with quote

nice article Smile and yes, pretty much like that, except taking it one step further, with a php script that will combine them into 1 file, and cache result for next time that combination of scripts is requested.
Quote:
Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.

I guess I'm looking for a more dynamic system of managing, optimizing, and combining JS and CSS files

and of course I looked into how many different combinations of scripts and css I was using, and optimizing and combining them all manually would probably take alot of time... likely more than I have Shocked

this is the combine script i spoke of
Code:
/************************************************************************

    * CSS and Javascript Combinator 0.5
    * Copyright 2006 by Niels Leenheer
    *
    * Permission is hereby granted, free of charge, to any person obtaining
    * a copy of this software and associated documentation files (the
    * "Software"), to deal in the Software without restriction, including
    * without limitation the rights to use, copy, modify, merge, publish,
    * distribute, sublicense, and/or sell copies of the Software, and to
    * permit persons to whom the Software is furnished to do so, subject to
    * the following conditions:
    *
    * The above copyright notice and this permission notice shall be
    * included in all copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */


   $cache      = true;
   $cachedir = dirname(__FILE__) . '/cache';
   $cssdir   = dirname(__FILE__) . '/css';
   $jsdir    = dirname(__FILE__) . '/javascript';

   // Determine the directory and type we should use
   switch ($_GET['type']) {
      case 'css':
         $base = realpath($cssdir);
         break;
      case 'javascript':
         $base = realpath($jsdir);
         break;
      default:
         header ("HTTP/1.0 503 Not Implemented");
         exit;
   };

   $type = $_GET['type'];
   $elements = explode(',', $_GET['files']);
   
   // Determine last modification date of the files
   $lastmodified = 0;
   while (list(,$element) = each($elements)) {
      $path = realpath($base . '/' . $element);
   
      if (($type == 'javascript' && substr($path, -3) != '.js') ||
         ($type == 'css' && substr($path, -4) != '.css')) {
         header ("HTTP/1.0 403 Forbidden");
         exit;   
      }
   
      if (substr($path, 0, strlen($base)) != $base || !file_exists($path)) {
         header ("HTTP/1.0 404 Not Found");
         exit;
      }
      
      $lastmodified = max($lastmodified, filemtime($path));
   }
   
   // Send Etag hash
   $hash = $lastmodified . '-' . md5($_GET['files']);
   header ("Etag: \"" . $hash . "\"");
   
   if (isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
      stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"')
   {
      // Return visit and no modifications, so do not send anything
      header ("HTTP/1.0 304 Not Modified");
      header ('Content-Length: 0');
   }
   else
   {
      // First time visit or files were modified
      if ($cache)
      {
         // Determine supported compression method
         $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
         $deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate');
   
         // Determine used compression method
         $encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none');
   
         // Check for buggy versions of Internet Explorer
         if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') &&
            preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
            $version = floatval($matches[1]);
            
            if ($version < 6)
               $encoding = 'none';
               
            if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1'))
               $encoding = 'none';
         }
         
         // Try the cache first to see if the combined files were already generated
         $cachefile = 'cache-' . $hash . '.' . $type . ($encoding != 'none' ? '.' . $encoding : '');
         
         if (file_exists($cachedir . '/' . $cachefile)) {
            if ($fp = fopen($cachedir . '/' . $cachefile, 'rb')) {

               if ($encoding != 'none') {
                  header ("Content-Encoding: " . $encoding);
               }
            
               header ("Content-Type: text/" . $type);
               header ("Content-Length: " . filesize($cachedir . '/' . $cachefile));
      
               fpassthru($fp);
               fclose($fp);
               exit;
            }
         }
      }
   
      // Get contents of the files
      $contents = '';
      reset($elements);
      while (list(,$element) = each($elements)) {
         $path = realpath($base . '/' . $element);
         $contents .= "\n\n" . file_get_contents($path);
      }
   
      // Send Content-Type
      header ("Content-Type: text/" . $type);
      
      if (isset($encoding) && $encoding != 'none')
      {
         // Send compressed contents
         $contents = gzencode($contents, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE);
         header ("Content-Encoding: " . $encoding);
         header ('Content-Length: ' . strlen($contents));
         echo $contents;
      }
      else
      {
         // Send regular contents
         header ('Content-Length: ' . strlen($contents));
         echo $contents;
      }

      // Store cache
      if ($cache) {
         if ($fp = fopen($cachedir . '/' . $cachefile, 'wb')) {
            fwrite($fp, $contents);
            fclose($fp);
         }
      }
   }   
   
 
kguske







PostPosted: Thu May 28, 2009 12:04 pm Reply with quote

I believe that would have similar results to the tool mentioned in the article IF the source JS and CSS have already been minified.

Also, I am not sure that gz compression really yields any overall benefit. The 2 components of performance relevant here are # of files and size of files. Combining the files addresses the former. The problem with addressing the latter via compression is that the client browser must decompress, which negates some (if not all) of the benefit of compressing. Although it might be easier on the server (though even that is debatable), the visitor likely won't notice a favorable improvement in performance from that change (also remember that browsers will cache the files after the first download).

As for the effort to combine scripts and CSS on the fly, I am considering that it might be best to combine and minify offline, and always load the files, even when specific pieces aren't required.
 
duck
Involved
Involved



Joined: Jul 03, 2006
Posts: 273

PostPosted: Thu May 28, 2009 1:18 pm Reply with quote

Actually to clarify it IS recommended that ALL JS be loaded at the end of the page where possible. Some JS needs to be loaded in the header but if it doesn't NEED to be loaded in the header it SHOULD be loaded last. This boosts performance of page load times and is the most Optimal way of handling JS. So when making a system for including JS dynamically attention should be paid to the choice of adding in the footer.
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Feedback/Suggestions

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©