Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



15 Commits

Repository files navigation


Dynamically handles assets inserted into the header and the footer, allowing you to enqueue your JS and CSS files, your meta tags, etc.

What's this for ?

Web performance best practices recommend that:

  • load all your stylesheets in the <HEAD>...</HEAD> portion of the page. In this way the browser loads stylesheets early and will use them to correctly render the page. If this rule is not followed, you are going to see pages that change their look and layout in the middle of loading - which is when the stylesheets have been loaded.

  • load all your Javascript at the bottom of the page just before the closing </BODY> tag. The <SCRIPT> tags block and freeze rendering of HTML by the browser, because potentially the Javascript can alter the contents of the page and modify its structure.

Following these rules, you will often need to prepare Javascript scripts and files, stylesheets and meta tags BEFORE are you ready to render a page. This is what Assoto is meant to help with. It will collect your assets in advance, and then deliver them when you start printing your page.


While preparing to render a page, you start accumulating your assets. This happens by stacking them in what is called "stacks". There are two stacks:

  • "head" (Assoto\Stack::STACK_HEAD) for the <HEAD>...</HEAD> portion of the page,
  • "footer" (Assoto\Stack::STACK_FOOTER) for the bottom of the page just before the closing </BODY> tag.

Following the best practices Assoto will put all your stylesheets in the "head", and all your scripts at the bottom in the "footer".

To see what's already added in a stack call Assoto\Stack::stack($stack). If you want to reset a stack and empty it call Assoto\Stack::reset($stack).

How to use ?

You start by stacking your assets.

	/* adds my.js as javascript file asset */

	/* adds my.css as stylesheet asset */

	/* adds the <title> tag as asset */
	Assoto\HTML::title('Hello World!');

When it is time to render the page, you call to Assoto\Stack::display() to print the accumulated assets in the stacks. Here's an example with a very crude PHP page:

<head><?php echo Assoto\Stack::display('head'); ?></head>

	<h1>Assoto Example</h1>

<?php echo Assoto\Stack::display('footer'); ?>

The rendered output will be

<head><link href="my.css" rel="stylesheet" type="text/css"/><title>Hello World!</title></head>

	<h1>Assoto Example</h1>

<script type="text/javascript" src="my.js"/>

That's it. Very simple and straight-forward. This will work with any type of template engine you use, it will just require some additional code to pass the accumulated assets.


There are several classes with canned methods for adding different types of assets: stylesheets, scripts, meta tags and links.

Under the hood all of them are actually calling Assoto\Stack::add() method. Depending on the type of the asset, these canned method are adding some additional default values, and pointing towards the correct stack.

  • Assoto\HTML::title("Hello World!") - adds <title>...</title> tags to "head" assets stack

  • Assoto\CSS::style("body{background:#fff}") - adds inline <style>...</style> block to "head" assets stack

  • Assoto\CSS::stylesheet("my.css") - adds CSS stylesheet "head" assets stack

  • Assoto\JS::inline("console.log(somevar);") - adds javascript inline <script>...</script> block to "footer" assets stack

  • Assoto\JS::file("my.js") - adds javascript file to "footer" assets stack

  • Assoto\Meta::link('//', 'dns-prefetch') - adds "dns-prefetch" link tag to "head" assets stack

  • Assoto\Meta::canonical('') - adds canonical link element to "head" assets stack

  • Assoto\Meta::icon('favicon.ico') - adds icon link to the "head" assets stack

  • Assoto\Meta::meta('keywords', 'assets, enqueue') - adds meta tag for "keywords" to the "head" assets stack

  • Assoto\Meta::property('og:type', 'website') - adds meta tag with property attribute (used for Open Graph Protocol) to the "head" assets stack

Identifying assets

Each asset added gets an "id". In some cases this identification is used to check if the assets already exists in a stack, and in some cases it is used to make sure that you only have one asset of that type.

You can manually set the "id" when calling the Assoto\Stack::add() method directly. Most of the canned methods also support providing assets "id" as one of their arguments. There are some that methods where the "id" argument is omitted on purpose since those assets can have only one instance - such as Assoto\Meta::canonical() and Assoto\HTML::title()

Let's have few assets stacked:

	Assoto\HTML::title('Hello World!');

Both of those assets are assigned to the "head" (Assoto/Stack::STACK_HEAD) stack. Let's have a look at that stack and see the "id" for each of those assets:

    [css:my.css] => <link href="my.css" rel="stylesheet" type="text/css"/>
    [html:title] => <title>Hello World!</title>

Assets that are files (such as stylesheets and javascript files) have their urls used to compose their ids. This works as prevention for adding the same assets file multiple times. You can call as many times as you want to add the same asset, but in the end it will be added only once, and this is achieved by locking to its "id".

To check if an asset exists in a stack call Assoto\Stack::exists($stack, $id). If you want to delete an already added asset call Assoto\Stack::delete($stack, $id).

More Examples

  • Inline favicon image
  • Hreflang alternative link tags
	Assoto\Meta::hreflang('//', 'de-de');
	Assoto\Meta::hreflang('//', 'en-ca');
  • Open Graph Protocol
	Assoto\Meta::property('og:image', ';v=4');
	Assoto\Meta::property('og:site_name', 'GitHub');
	Assoto\Meta::property('og:type', 'object');
	Assoto\Meta::property('og:title', 'kktsvetkov/Assoto');
	Assoto\Meta::property('og:url', '');
	Assoto\Meta::property('fb:app_id', '1401488693436528');
  • Google Site Verification
	Assoto\Meta::meta('google-site-verification', 'KT5gs8h0wvaagLKAVWq8bbeNwnZZK1r1XQysX3xurLU');
  • Atom Feed
		'', // empty id, let the id be auto-generated
			'type' => 'application/atom+xml',
			'title' => 'Recent Commits to Assoto'
  • Apple Touch Icons
		'', // empty id, let the id be auto-generated
		array('sizes' => '114x114')
  • Bootstrap Javascript File
 	'', // empty id, let the id be auto-generated
 		'integrity' => 'sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa',
 	 	'crossorigin' => 'anonymous',


Simple assets management for enqueuing your JS and CSS files, your meta tags, etc.








No packages published