2.0+
Resource class
Resource urls (< 2.0)
The resource class already makes it possible to group static urls into specified group names through the Res::name() method just as shown below:
<php? 

Res::new() 

      ->name('headers')
        ->url('some_css_url_1.css')
        ->url('some_css_url_2.css')
        ->url('some_js_url.js')

      ->name('footers')
        ->url('some_css_url_1.css')
        ->url('some_css_url_2.css')
        ->url('some_js_url.js')
        
      ->urlClose();

    
Once the group names are defined, we can then go on to import the groups into the template file with the defined group names using the @res() directive
@res(':header') //import all declared header urls
    

We can also use the <?= Res::import() ?> method similarly outside the template file. Only the urls in the called group will be imported to the webpage rather than having to call them one after the other in multiple files. While this is easy to use, one major issue could be that if we need a url from another group into a new group, we need to set the group name and url again. If we happen to use the same url in multiple groups and the list is long, it may be difficult to manage a url multiple times especially if we have to change the path of a file. In order to resolve this issue, version 2.0 provides new methods which helps to properly name urls making it easier to manage all urls as deemed fit.


Resource urls (2.0+)
In version 2.0, each url can be given a unique name that makes it easier to call it as a group or as an single file.

<php? 

Res::new() 

      ->name('headers')
        ->url('some_css_url_1.css')->named('css1') //set unique name
        ->url('some_css_url_2.css')->named('css2')
        ->url('some_js_url.js')->named('js1')

      ->name('footers')
        ->url('js_url_1.js')
        ->url('js_url_2.css')->named('js2')
        
      ->urlClose();

    
@recall('css1', 'css2', 'js2') //call files by unique name
    
In route files, we can also use the Res::recall() method or the recall() helper function to achieve a similar response. While the recall() function is similar to @recall() directive, the Res::recall() is slightly different as it can only call a single unique name at a time.

<?php

Res::recall('css1'); //calling unique name returns a script or list of scripts
Res::recall('css1', true); //calling unique name returns an array of scripts
    
The second line above is useful in helping to know the number of scripts existing in a single unique group. This is not possible in the first line because it returns a string rather than an array. In cases where multiple unique names are required, then the helper function recall() makes this operation easier. However, since the files are used within template files, the directive @recall() or @load() will at most times be used. The introduction of these approaches even makes it easier to generate groups using defined names rather than their real path.

<php? 

Res::new() 

      ->name('headers')
        ->url('some_css_url_1.css')->named('css1')
        ->url('some_css_url_2.css')->named('css2')
        ->url('some_js_url.js')->named('js1')

      ->name('footers')
        ->url('js_url_1.js')
        ->url('js_url_2.css')->named('js2')
        
      ->bind('cssgroup', ['css1','css2'])
      ->bind('jsgroup', ['js1','js2'])
        
      ->urlClose();
    
@recall('cssgroup') //each script of specified group will be returned to the webpage.
    
In the example above, new groups were created using the uniquely specified names of the stored file urls. Once the group is created with its unique name, then name can then be used in the template files. It is essential to know that the bind() method's group name supplied as the first argument must be unique name. The resource methods named(), bind() and bindTo() all share the same unique storage space. This means that any name supplied in any of these methods cannot be unique in another method of the same group although, the bindTo() method is slightly different. This is shown below:
<php? 

Res::new() 

      ->name('headers')
        ->url('some_css_url_1.css')->named('css1')
        ->url('some_css_url_2.css')->named('css2')
        ->url('some_js_url.js')->named('js1')
        ->bindTo('headers')
        
      ->name('footers')
        ->url('js_url_1.js')
        ->url('js_url_2.css')->named('js2')
        ->bindTo('footers')
        ->bindTo('headers', ['js2'])  

      ->bind('cssgroup', ['css1','css2'])
      ->bind('jsgroup', ['js1','js2'])
        
      ->urlClose();
    
The example above explains how the bindTo() method works. The code structure is explained below:

  • When bindTo() is used immediately after a set of named urls, it binds only the previously named urls into a new unique group. The new unique group name has nothing to do with the one defined through the global name(). For example, the bindTo('headers') will add all the previously named urls into the supplied unique name "headers" while in the case of bindTo('footers') only the named url "js2" will be added to the new unique group name.

  • The method supports adding more files to a previously declared group, however, two arguments must be supplied. The first argument is the existing unique name while the second argument is the array containing unique names of urls to be added to the group. For example, in the above bindTo('headers', ['js2']) adds the url of "js2" to existing unique group "headers"

  • When bindTo() is used, all named urls before it will be added into the new group regardless of their parent groups. Once the method is used, the previous named groups will be safely exited without affecting their unique names.



Notice
  • The custom global urls are stored and loaded from the res/res.php file. The main static files declaration have been moved to a more private directory core/res.php to remove visual noise.
  • While the names "headers" and "footers" are reserved, more urls can be added into them. This can be done by either using bindTo() for unique names or by using the name() method for global namespace.
  • Methods that shares unique name space cannot redefine a unique name. These methods are named(), bind() and bindTo(). The bindTo() can only add more urls, it cannot redeclare an existing name unless the entire class is started on a strict mode using the urlOpen(true) method which entirely clears all previous declarations.
  • When a non-existing unique name is called, an empty string is returned. However, if a unique name is redeclared, an error is thrown.