Skip to content

A simple assets library. Combine, minify, and cache your JS and CSS assets.

Notifications You must be signed in to change notification settings

th3fallen/assets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assets

Build Status

Assets is yet another CSS/JavaScript minificaton and combination library. However, unlike most other libraries (which rely on Assetic), this takes a much more simplistic approach.

Assets supports minifying and combining stylesheets and scripts, in order to reduce the number and size of http requests need to load a given page. Also, the generated file is also cached, which will prevent an application from having to generate the same file with every new request.

Basic usage

CSS

CSS files can be added using the following command, where "file1.css" and "file2.css" are the CSS files you want to include, and are located at assets/css/file1.css and assets/css/file2.css.

Assets::css('file1.css');
Assets::css('file2.css');

You may also submit files as an array.

Assets::css(array('file1.css', 'file2.css'));

By default, Assets will minify both of these files and combine them into a single file (which is written to 'assets/cache' directory). To include this file in your page, use the following:

echo Assets::render_css();
/*
Returns something like:
<link rel="stylesheet" href="/assets/cache/3cf89b9f723e22c1caf26f8d4d1fdc31.css">
*/

JS

Javascript files can be added using the following command, where "file1.js" and "file2.js" are the javascript files you want to include, and are located at assets/js/file1.js and assets/js/file2.js.

Assets::js('file1.js');
Assets::js('file2.js');

You may also submit files as an array.

Assets::js(array('file1.js', 'file2.js'));

By default, Assets will minify both of these files and combine them into a single file (which is written to 'assets/cache' directory). To include this file in your page, use the following:

echo Assets::render_js();
/*
Returns something like:
<script src="/assets/cache/9cf2803d8f075cb7d1ad31940738f35e.js"></script>
*/

If you like to generate the CSS and JS tags together, you can call:

echo Assets::render();
/*
Which will return:
<link rel="stylesheet" href="/assets/cache/3cf89b9f723e22c1caf26f8d4d1fdc31.css">
<script src="/assets/cache/9cf2803d8f075cb7d1ad31940738f35e.js"></script>
*/

Configuration

By default, this library assumes the following directory structure:

assets/
   css/
   js/
   cache/
   

However, you are now able to adjust the path to the assets directory (if needed):

Assets::setPath('public/assets/'));

BaseURL

Assets::setBaseurl('/'));

Groups

This library currently does not offer support for groups. This is because the project I was working on did not require it. If enough requests are made, this may be added in a future version.

Thanks

This asset library was inspired and uses components from the following libraries:

Contributing

If you've got any issues/complaints/suggestions, please tell me and I'll do my best!

About

A simple assets library. Combine, minify, and cache your JS and CSS assets.

Resources

Stars

Watchers

Forks

Packages

No packages published