Download the PHP package imansa/assetter without Composer
On this page you can find all versions of the php package imansa/assetter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download imansa/assetter
More information about imansa/assetter
Files in imansa/assetter
Package assetter
Short Description Assets manager for PHP. Allow manage CSS and JS files in website and its dependencies. Also allows refresh cache in browsers by adding revisions of loaded files.
License MIT
Homepage https://github.com/imansa/assetter
Informations about the package assetter
Assetter
Assets manager for PHP. Allow manage CSS and JS files in website and its dependencies. Also allows refresh cache in browsers by adding revisions of loaded files. Assetter allows you to register namespaces for files paths fo better managing if required.
Installation
Via composer.json
Via Composer CLI
Table of contents
- Basics
- Define collection array
- Create Assetter object
- Load some libraries
- Show loaded files in document
- Namespaces
- Register namespace
- Usage registered namespaces
- LESS ans SCSS Compilers
- Usage
Basics
1. Define collection array
First, you have to create array with collection of files.
Here is full indexed array of one element in collection.
- scripts - Stores array of JavaScript files paths (sigle value (as string) NOT ALLOWED).
- styles - Stores array of CSS files paths (sigle value (as string) NOT ALLOWED).
- require - Stores array of names of libraries/assets (elements from collection) that must be loaded with this library. Dependencies.
- order - Number of position in loaded files. Lower number = higher in list.
- group - Group this library belongs to.
2. Create Assetter object
Now we have to create object of Assetter. To work with Assetter You have to create collection (array) of assets that Assetter can manage.
3. Require some libraries
Now, we can require some libraries. Here we require our theme
asset, which required also jquery
asset.
4. Show required files in document
We have required our files. Now it's time to show it in document. To do this, You have to build a collection for group of the assets, and then get the rendered assets.
To render the assets tags use one of the following method using the group.
Namespaces
You can define namespaces, that will be applied for every asset path, which use it. Think of namespace (in this case) like some Root path to somethig, like root path to images in your project, or to (more for this) assets path. You can register multiple namespaces, and use multiple namespaces in paths to files for assets. What u need.
1. Register namespace
To register namespace, call belowed method. First argument is the name of namespace, you want to register. Second argument is a path to some directory. Followed code shows, how register two namespaces.
REMEMBER - register namespaces before load any asset. Namespaces works only when is needed, so only when you load (or append) any asset. Registered namespaces after load or append won't work.
2. Usage registered namespaces
When we have registered namespaces, we only now have to add name of namespace to these files path, we need to. Followed example, shows two assets, one works with namespace, second - without.
Namespace can be named as you want, here i provide proposal, you can use any way of name convencion, like: {NS}, [NS], %NS, |NS|, -NS, and combine small and big letters as names. But remember to add some special characters. Assetter uses str_replace for seach and replace namespaces, so if you named namespace with only letters, some assets paths can be damaged.
How to require CSS in \ and JS in \?
This separation of the elements is a common technique, tha allows web browsers renders a fully styled content, without rendering and downloading any JavaScripts at the beginning. Nowadays we require so many JS libs in our websites, all those files must be downloaded by browser at the place of occurence. Moving those files at the end of the body speeds up the page load.
To achive that, You have to define the head
and the body
part of the asset, and then mix them together into one,
like this:
That defined asset You have to only require using the mixed name bootstrap
. Assetter take care of the
rest of the assets, and build them into proper defined group in building time.
Last part, you have to only build assets separate for HEAD and for the BODY.