Giter VIP home page Giter VIP logo

assetic's Introduction

Assetic Build Status

Assetic is an asset management framework for PHP.

Project status

This project is not maintained anymore. Development has been taken over at https://github.com/assetic-php/assetic under the package name assetic/framework.

Example

<?php

use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;

$js = new AssetCollection(array(
    new GlobAsset('/path/to/js/*'),
    new FileAsset('/path/to/another.js'),
));

// the code is merged when the asset is dumped
echo $js->dump();

Assets

An Assetic asset is something with filterable content that can be loaded and dumped. An asset also includes metadata, some of which can be manipulated and some of which is immutable.

Property Accessor Mutator
content getContent setContent
mtime getLastModified n/a
source root getSourceRoot n/a
source path getSourcePath n/a
target path getTargetPath setTargetPath

The "target path" property denotes where an asset (or an collection of assets) should be dumped.

Filters

Filters can be applied to manipulate assets.

<?php

use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\Filter\LessFilter;
use Assetic\Filter\Yui;

$css = new AssetCollection(array(
    new FileAsset('/path/to/src/styles.less', array(new LessFilter())),
    new GlobAsset('/path/to/css/*'),
), array(
    new Yui\CssCompressorFilter('/path/to/yuicompressor.jar'),
));

// this will echo CSS compiled by LESS and compressed by YUI
echo $css->dump();

The filters applied to the collection will cascade to each asset leaf if you iterate over it.

<?php

foreach ($css as $leaf) {
    // each leaf is compressed by YUI
    echo $leaf->dump();
}

The core provides the following filters in the Assetic\Filter namespace:

  • AutoprefixerFilter: Parse and update vendor-specific properties using autoprefixer
  • CoffeeScriptFilter: compiles CoffeeScript into Javascript
  • CompassFilter: Compass CSS authoring framework
  • CssEmbedFilter: embeds image data in your stylesheets
  • CssImportFilter: inlines imported stylesheets
  • CssMinFilter: minifies CSS
  • CleanCssFilter: minifies CSS
  • CssRewriteFilter: fixes relative URLs in CSS assets when moving to a new URL
  • DartFilter: compiles Javascript using dart2js
  • EmberPrecompileFilter: precompiles Handlebars templates into Javascript for use in the Ember.js framework
  • GoogleClosure\CompilerApiFilter: compiles Javascript using the Google Closure Compiler API
  • GoogleClosure\CompilerJarFilter: compiles Javascript using the Google Closure Compiler JAR
  • GssFilter: compliles CSS using the Google Closure Stylesheets Compiler
  • HandlebarsFilter: compiles Handlebars templates into Javascript
  • JpegoptimFilter: optimize your JPEGs
  • JpegtranFilter: optimize your JPEGs
  • JSMinFilter: minifies Javascript
  • JSMinPlusFilter: minifies Javascript
  • JSqueezeFilter: compresses Javascript
  • LessFilter: parses LESS into CSS (using less.js with node.js)
  • LessphpFilter: parses LESS into CSS (using lessphp)
  • OptiPngFilter: optimize your PNGs
  • PackagerFilter: parses Javascript for packager tags
  • PackerFilter: compresses Javascript using Dean Edwards's Packer
  • PhpCssEmbedFilter: embeds image data in your stylesheet
  • PngoutFilter: optimize your PNGs
  • ReactJsxFilter: compiles React JSX into JavaScript
  • Sass\SassFilter: parses SASS into CSS
  • Sass\ScssFilter: parses SCSS into CSS
  • SassphpFilter: parses Sass into CSS using the sassphp bindings for Libsass
  • ScssphpFilter: parses SCSS using scssphp
  • SeparatorFilter: inserts a separator between assets to prevent merge failures
  • SprocketsFilter: Sprockets Javascript dependency management
  • StylusFilter: parses STYL into CSS
  • TypeScriptFilter: parses TypeScript into Javascript
  • UglifyCssFilter: minifies CSS
  • UglifyJs2Filter: minifies Javascript
  • UglifyJsFilter: minifies Javascript
  • Yui\CssCompressorFilter: compresses CSS using the YUI compressor
  • Yui\JsCompressorFilter: compresses Javascript using the YUI compressor

Asset Manager

An asset manager is provided for organizing assets.

<?php

use Assetic\AssetManager;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;

$am = new AssetManager();
$am->set('jquery', new FileAsset('/path/to/jquery.js'));
$am->set('base_css', new GlobAsset('/path/to/css/*'));

The asset manager can also be used to reference assets to avoid duplication.

<?php

use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetReference;
use Assetic\Asset\FileAsset;

$am->set('my_plugin', new AssetCollection(array(
    new AssetReference($am, 'jquery'),
    new FileAsset('/path/to/jquery.plugin.js'),
)));

Filter Manager

A filter manager is also provided for organizing filters.

<?php

use Assetic\FilterManager;
use Assetic\Filter\Sass\SassFilter;
use Assetic\Filter\Yui;

$fm = new FilterManager();
$fm->set('sass', new SassFilter('/path/to/parser/sass'));
$fm->set('yui_css', new Yui\CssCompressorFilter('/path/to/yuicompressor.jar'));

Asset Factory

If you'd rather not create all these objects by hand, you can use the asset factory, which will do most of the work for you.

<?php

use Assetic\Factory\AssetFactory;

$factory = new AssetFactory('/path/to/asset/directory/');
$factory->setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDebug(true);

$css = $factory->createAsset(array(
    '@reset',         // load the asset manager's "reset" asset
    'css/src/*.scss', // load every scss files from "/path/to/asset/directory/css/src/"
), array(
    'scss',           // filter through the filter manager's "scss" filter
    '?yui_css',       // don't use this filter in debug mode
));

echo $css->dump();

The AssetFactory is constructed with a root directory which is used as the base directory for relative asset paths.

Prefixing a filter name with a question mark, as yui_css is here, will cause that filter to be omitted when the factory is in debug mode.

You can also register Workers on the factory and all assets created by it will be passed to the worker's process() method before being returned. See Cache Busting below for an example.

Dumping Assets to static files

You can dump all the assets an AssetManager holds to files in a directory. This will probably be below your webserver's document root so the files can be served statically.

<?php

use Assetic\AssetWriter;

$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);

This will make use of the assets' target path.

Cache Busting

If you serve your assets from static files as just described, you can use the CacheBustingWorker to rewrite the target paths for assets. It will insert an identifier before the filename extension that is unique for a particular version of the asset.

This identifier is based on the modification time of the asset and will also take depended-on assets into consideration if the applied filters support it.

<?php

use Assetic\Factory\AssetFactory;
use Assetic\Factory\Worker\CacheBustingWorker;

$factory = new AssetFactory('/path/to/asset/directory/');
$factory->setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDebug(true);
$factory->addWorker(new CacheBustingWorker());

$css = $factory->createAsset(array(
    '@reset',         // load the asset manager's "reset" asset
    'css/src/*.scss', // load every scss files from "/path/to/asset/directory/css/src/"
), array(
    'scss',           // filter through the filter manager's "scss" filter
    '?yui_css',       // don't use this filter in debug mode
));

echo $css->dump();

Internal caching

A simple caching mechanism is provided to avoid unnecessary work.

<?php

use Assetic\Asset\AssetCache;
use Assetic\Asset\FileAsset;
use Assetic\Cache\FilesystemCache;
use Assetic\Filter\Yui;

$yui = new Yui\JsCompressorFilter('/path/to/yuicompressor.jar');
$js = new AssetCache(
    new FileAsset('/path/to/some.js', array($yui)),
    new FilesystemCache('/path/to/cache')
);

// the YUI compressor will only run on the first call
$js->dump();
$js->dump();
$js->dump();

Twig

To use the Assetic Twig extension you must register it to your Twig environment:

<?php

$twig->addExtension(new AsseticExtension($factory));

Once in place, the extension exposes a stylesheets and a javascripts tag with a syntax similar to what the asset factory uses:

{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %}
    <link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}

This example will render one link element on the page that includes a URL where the filtered asset can be found.

When the extension is in debug mode, this same tag will render multiple link elements, one for each asset referenced by the css/src/*.sass glob. The specified filters will still be applied, unless they are marked as optional using the ? prefix.

This behavior can also be triggered by setting a debug attribute on the tag:

{% stylesheets 'css/*' debug=true %} ... {% stylesheets %}

These assets need to be written to the web directory so these URLs don't return 404 errors.

<?php

use Assetic\AssetWriter;
use Assetic\Extension\Twig\TwigFormulaLoader;
use Assetic\Extension\Twig\TwigResource;
use Assetic\Factory\LazyAssetManager;

$am = new LazyAssetManager($factory);

// enable loading assets from twig templates
$am->setLoader('twig', new TwigFormulaLoader($twig));

// loop through all your templates
foreach ($templates as $template) {
    $resource = new TwigResource($twigLoader, $template);
    $am->addResource($resource, 'twig');
}

$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);

Assetic is based on the Python webassets library (available on GitHub).

assetic's People

Contributors

abretaud avatar alexash avatar amyboyd avatar benoitleveque avatar brikou avatar brunoais avatar cedriclombardot avatar dbu avatar ecentinela avatar fran6co avatar hason avatar heristop avatar jeroenvisser101 avatar joec4i avatar kastaneda avatar keyvanakbary avatar krichprollsch avatar kriswallsmith avatar krmarien avatar maximilian-walter avatar mente avatar moox avatar mpdude avatar nettles-jarrod avatar pierredup avatar rejinka avatar schmittjoh avatar speckins avatar stof avatar yguedidi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assetic's Issues

SassFilter under WAMP

After installing Ruby from http://rubyforge.org/frs/download.php/74298/rubyinstaller-1.9.2-p180.exe
Running gem install haml
And changing assetic.sass_bin in properties.ini

I ran into problems runnning php app/console assetic:dump

There are a couple of problems (also outlined here by Arjen Brouwer: http://groups.google.com/group/symfony-devs/browse_thread/thread/3cdcdf89e7020723):

  1. A trailing slash in --cache-location:
    [RuntimeException]
    The filename, directory name, or volume label syntax is incorrect.
  2. Quotes around the sass executable, e.g. "C:\Ruby192\bin\sass" "--scss"
    [RuntimeException]
    The filename, directory name, or volume label syntax is incorrect.
  3. And finally there is a problem with the Process class which sets the default value for $env to an empty array, but according to the documentation this should be NULL (http://nl.php.net/manual/en/function.proc-open.php). For some reason this gave problems in my Windows setup:
    [RuntimeException]
    '"ruby.exe"' is not recognized as an internal or external command,

After removing the trailing slash:
$options[] = trim($this->cacheLocation, '');

Changing the instantiation of $proc:
// remove $this->sassPath from $options array
$proc = new Process($this->sassPath . ' ' . implode(' ', array_map('escapeshellarg', $options)));

And passing NULL as the $env parameter I was able to get things working.

Regards,

Sander

Compass @Import

Hello again,

I got some questions about the @import. I'm facing two problems:

  1. I'm in a bundle and want to import my main.scss located at: /app/Resources/sass/main.scss i tried everything without success, is there a solution for that?

  2. Complementing the first one, i use a trick that for me don't make sense, i make something like that:

@import url(/sass/main.scss) that will get the folder: "web/sass/main.scss" but then i got errors and it doesn't import it like was expected. Any hint on that?

I don't know if it's possible to import like that: @import "@MyBundle/Resources/sass/main.scss"

Thanks

FireSass Integration

An issue arises when you enable sass' "--debug-info". Debug output works fine however the file that it references too is a temporary file that was created and deleted through the assetic filter process.

The requirement form Sass' perspective is to process the file directly. The location of the file will then be printed in the output.

FireSass is a FireFox addon which processes (displays) these debug statements to a developer trying to locate where certain css declarations have been made.

I'm sure there is other applications that process these debug statements but for the time being FireSass does so well.

Image optimization

This is an interesting project and it reminds me of what I've done for File Conveyor (http://fileconveyor.org/). It basically is a subset of File Conveyor's functionality: it's only the the "processor" functionality, but obviously assetic is much easier to integrate.

The major thing that's still missing though, is image optimization. By "image optimization", I mean lossless image optimization, like smush.it does. Clearly, this adds additional server/set-up requirements, but it's still a very handy service.

Also, does assetic automatically detect when files have changed and then rebuilds the cache?

node.js + less under windows

Under windows, node.js requires cygwin to be used properly.
But this introduces an issue when using assetic + node/less under windows.

Assetic tries to execute a command like :

node C:\cygwin\tmp\ass37F5.tmp

But under windows, node needs to be run by using unix style paths (and so through cygwin drives). The previous command fails, but the following works well :

node /cygdrive/c/tmp/ass37F5.tmp

I'm not sure how to properly fix this but we can't use Assetic & Less because of that.

Error when include 2 files with the same name

When I try to include 2 files from 2 different places, for example:

{% stylesheets '@TestBundle/Resources/public/css/index.css' '@DemoBundle/Resources/public/css/index.css' %}
    <link href="{{ asset_url }}" rel="stylesheet" type="text/css" />
{% endstylesheets %}

It takes the first one and duplicate it to the second one, generate the same file twice.

Prevent duplicate assets

I think the same asset added to a collection multiple times will be merged in multiple times...

Loading problem

It seems that the latest changes didn't work (I have the latest Symfony and vendors code)

In Twig template:

{% javascripts 'js/library/jquery/*' 'js/OS/*' 'js/*.js' %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

View source:

<script src="/app_dev.php/js/dc0250b_part1_jquery-1.4.2.min1.js" type="text/javascript"></script>
<script src="/app_dev.php/js/dc0250b_part1_jquery.cookie.min2.js" type="text/javascript"></script>
<script src="/app_dev.php/js/dc0250b_part1_jquery.elastic-1.6.4.min3.js" type="text/javascript"></script>
<script src="/app_dev.php/js/dc0250b_part1_jquery.infieldlabel.min4.js" type="text/javascript"></script>
<script src="/app_dev.php/js/dc0250b_part2_OS2.js" type="text/javascript"></script>
<script src="/app_dev.php/js/dc0250b_part3_general1.js" type="text/javascript"></script>

For some reason anything after part1 failed to load correctly, and causes part1 scripts to point to them:
.._part1_jquery-1.4.2.min1.js => .._part2_OS1.js
.._part1_jquery.cookie.min2.js => .._part3_general1.js

And when clicking on .._part2_OS1.js I get the following error:

/*
[exception] 404 | Not Found | Symfony\Component\HttpKernel\Exception\NotFoundHttpException
[message] The "dc0250b" asset does not include a leaf at position 13.
[1] Symfony\Component\HttpKernel\Exception\NotFoundHttpException: The "dc0250b" asset does not include a leaf at position 13.
                at n/a
                    in /.../vendor/symfony/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php line 48

                at Symfony\Bundle\AsseticBundle\Controller\AsseticController->render('dc0250b', '13')

                at call_user_func_array(array(object(Symfony\Bundle\AsseticBundle\Controller\AsseticController), 'render'), array('dc0250b', '13'))
                    in /.../app/bootstrap.php.cache line 422

                at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Symfony\Component\HttpFoundation\Request), '1')
                    in /.../app/bootstrap.php.cache line 400

                at Symfony\Component\HttpKernel\HttpKernel->handle(object(Symfony\Component\HttpFoundation\Request), '1', true)
                    in /.../vendor/symfony/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php line 35

                at Symfony\Bundle\FrameworkBundle\HttpKernel->handle(object(Symfony\Component\HttpFoundation\Request), '1', true)
                    in /.../app/bootstrap.php.cache line 587

                at Symfony\Component\HttpKernel\Kernel->handle(object(Symfony\Component\HttpFoundation\Request))
                    in /.../web/app_dev.php line 19


*/

mtime regression

I have following configuration in symfony:

assetic:
    filters:
        scss:
            apply_to: "\.scss$"
        cssrewrite:
            apply_to: "\.css$"

Before commit "mtime-aware" 50d19c4 it worked. 4fffe72 works.
But now the scss filter is not applied anymore.

CssRewriteFilter

A filter to rewrite relative url() references in stylesheets.

assetic:dump and --no-debug

Hi,
With latest symfony and assetic from git, I have a problem with the assetic:dump command.
I use filter='?yui_css' to minify my css only in production mode.
When I run assetic:dump, I have to add the --no-debug option. If I don't do that, the generated production css are not minified (they are not in minified in dev mode, which is fine).

I find a bit confusing to add the --no-debug option to make it work as intended. Do you think we could avoid that?
thanks

(I was not sure if I needed to create this issue here or on the symfony project...)

Add Autoloader class

I'm currently using following code in my project.

<?php
/**
 * Autoloads Assetic classes.
 *
 * @author  Joeri Verdeyen <[email protected]>
 */
class Assetic_Autoloader
{
    /**
     * Registers Assetic_Autoloader as an SPL autoloader.
     */
    static public function register()
    {
        ini_set('unserialize_callback_func', 'spl_autoload_call');
        spl_autoload_register(array(new self, 'autoload'));
    }

    /**
     * Handles autoloading of classes.
     *
     * @param  string  $class  A class name.
     *
     * @return boolean Returns true if the class has been loaded
     */
    static public function autoload($class)
    {
        if (0 !== strpos($class, 'Assetic')) {
            return;
        }

        if (file_exists($file = dirname(__FILE__).'/../'.str_replace('\\', '/', $class).'.php')) {
            require $file;
        }

    }
}
require_once(dirname(__FILE__).'/vendor/Assetic/Assetic/Autoloader.php');
\Assetic_Autoloader::register();

Sometimes the CSS and/or JS does not load.

I'm using assetic and sometimes (seemingly at random) random css and/or js files do not load. This happens on almost every request. If I refresh enough times, I can eventually get a request that successfully loads all of the files, only to reload and have them broken again.

The CSS:

{% stylesheets 'Resources/css/*.css' '@LimelightBundle/Resources/css/main.css' filter='?yui_css' %}
    <link href="{{ asset_url }}" media="screen, projection" rel="stylesheet" />
{% endstylesheets %}

The JS:

{% javascripts filter='?yui_js'
                'Resources/js/jquery.js'
                'Resources/js/history/scripts/compressed/json2.js'
                'Resources/js/jquery-ui.min.js'
                'Resources/js/amplify.js'
                'Resources/js/history/scripts/compressed/history.adapter.jquery.js'
                'Resources/js/history/scripts/compressed/history.js'
                'Resources/js/jquery.colorbox-min.js'
                'Resources/js/jquery.qtip.js'
                'Resources/js/limelight.main.js'
            %}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}
assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        yui_css:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"
        yui_js:
            jar: "%kernel.root_dir%/Resources/java/yuicompressor.jar"

Debug is set to true, use_controller is true (in dev). When I look at the source, I get messages like these:

Failed to load source for: http://limelight.local/app_dev.php/js/00b37c0_jquery_1.js

If I manually go to that URL I get the correct javascript file. Not sure what's going on here...

Dump command output files

Hey,

I know I didn't post this in the dump command's repository but bear with me.

Runnin app/console assetic:dump --no-debug for a template containing:

{% block stylesheets %}
    {% stylesheets '@MyBundle/Resources/scss/app.scss' filter='compass' output='css/app.css' %}
        <link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
    {% endstylesheets %}
{% endblock %}

Would create 2 files in web/css: 370f011.css and app.css, both with the same content (correctly processed css).
Is this normal behavior? (the command creates more than one file?)
If I ommit the --no-debug argument, I get 4 files (there are 2 copies with the names xx_1.css).
If I ommit the output argument in the template I get only 370f011.css.

[Process] Large resource files js/css (on Windows)

Maybe this happens on linux too. I tried to compile simple js-Files trough mingw32 command line (used for git) on windows.

{% javascripts filter='yui_js' output='cdn/scripts.js' 'js/jquery-1.6.js'
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

in a twig-Template. The issues was that i just stopped at [file+] C:\dev\../web/cdn/scripts.js without any notice or anything else happening. I just hang.

I debugged it down to the Process-class. Problem lies within the fgets($pipes[2], 1024) line of the run-method. I will attach a code fix in some minutes that solves this problem.

TwigHelper should allow Versioning by MD5

It would be great if the twig functions javascripts and stylesheets would not only provide {{ asset_url }} but {{ asset_hash }} aswell, so that you can optionally do:

<script src="{{asset_url}}?v={{asset_hash}}">

automatically inline assets based on a cookie

problem:
i am sure i read this approach in some article but i cannot find it atm.
the basic issue this is trying to solve is users coming to the site with an empty cache:
http://yuiblog.com/blog/2007/01/04/performance-research-part-2/

they will have to wait for not only the html to return, but they will also have to wait for all the standard assets to load like icons, logos, css, javascript etc.

alternative approaches:
now one approach to reduce the impact of this issue is to use chunked response like rails 3.1 will support:
http://weblog.rubyonrails.org/2011/4/18/why-http-streaming

however this adds severe limitations on how templating can work.
relying on a revers proxy to handle this (varnish 3.1 may support chunked responses with ESI) is also not ideal since for example its quite tricky to then serve up a proper <title> tag to make SEO guys happy

better approach:
at any rate another approach which afaik is used by some of the big guys is to basically store in a cookie which assets are loaded already. then you can automatically decide to inline the assets that are not yet marked as loaded in the cookie.

now when the page is loaded, the client can receive a list with assets that are not yet checked off in the cookie and start loading these assets asynchronously after the user has already received the final page with the inlined assets. as these assets finish loading they are added to the cookie.

on the next request again you check which assets you need are not yet loaded which again get inlined. but obviously as things get loaded asynchronously eventually no asset will need to be inline anymore as the cache will be fully primed.

the assets remembered in the cookie can be fully versioned which will also deal with users having the cache go cold as assets might expire or will get updated.

whats needed:

  1. a way to define the assets that should be handled this way
  2. output twig filters need to be aware of which assets need to be inline based on this configuration and the configurable cookie name
  3. javascript module to handle the async loading

sanity check:
this should be a feature request with very low priority as its a pretty extreme optimization that most people dont need.

CompassFilter broken

Hey,
The new CompassFilter seems to be throwing around all sorts of errors on Win7.
The compass version may be the culprit too but I doubt it.
Can anyone tell me if this has been tested and on which compass version?
Thanks

Bug in regex in CssRewriteFilter

Hi,
I think there's a mistake in the 2 regex used in CssRewriteFilter (at the end of filterDump).
The problem is that (?.*) allow any character, including ')' which means that if you have several url(foo) in the same css, the matches are wrong. An example:

foo {
background-image: url(foobar);
padding: whatever;
}
bar {
background-image: url(barfoo);
}

with the current regex, you end up matching

foobar);
padding: whatever;
}
bar {
background-image: url(barfoo

I corrected it with something like it: '/url((["']?)(?[^)]*)(\1))/'
The problem should be the same for import regex.
Maybe there's a better solution?

Assetic is not aware of asset dependencies

As discussed here there is a problem with the new implementation of the compass binary.
The problem is that, the cache system, checks the timestamp of the sass file without involving the filter.
So if you have a main file which imports other "subfiles" (a typical situation working with compass) and you never edit this main file you never get a recompile.

The process of check the timestamp of an assetic file should in some way involve the filter to get a complete list of files to check and eventually trigger the recompile by checking all the timestamps.

This issue is related to compass, but I think it should also appear in Sass and ScssFilter and also on any filter that deal with an asset with a tree of subassets

Assetic debug mode in Symfony2 beta1 partly broken

Hi.
In a small symfony2 project, we just started using assetic.

        {% stylesheets output="bundles/lt/css/build.css"  '@LTBundle/Resources/public/css/style.css' %}
        <link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
        {% endstylesheets %}

This works well in production, generating links like:

<link href="/lt/bundles/lt/css/build.css" type="text/css" rel="stylesheet" /> 

However in dev environment, with the debug flag on (use_controller is still false!), it generates links like:

<link href="/lt/bundles/lt/css/build_style1.css" type="text/css" rel="stylesheet" /> 

But this file is not written by assetic:dump, instead always css/build.css is written like in the prod environment. So in dev environment the css file cannot be found.
Here is the config.yml part for assetic:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        # closure:
        #     jar: %kernel.root_dir%/java/compiler.jar
        # yui_css:
        #     jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar

In config_dev.yml, use_controllers was set to false, because otherwise relative image urls will not work any more due to the changed path of the css file (the URL includes the controller, so that the relative images will not be found any more). Do you have a tip for me to make it work also with use_controller: true?

Thanks for considering and for any help. It will be most appreciated.
And thanks for making such a great tool!

Best regards, mg

Image Manipulation

It seems to me that as well as the image optimisation already possible that it would be good to be able to do other image manipulation with Assetic to get the benefits of its caching/dumping of the results. I thought I would have a play about at creating a basic filter to do this. The first issue I have run into is that I cannot see anyway to get options from the Twig template or formula into the filter, I can only see it being possible via the service definition. That though fixes it for all uses of the filter, whereas it would be useful to be able to set options such as height and width for resizing on a per image basis.

Is this already possible? If not is it something it would make sense to add or is there a good reason not to?

sass/scss filter: @import issue

Hello,

Because of the fact that filtering is done for the file content, not a file itself, it is impossible to use @import in scss files. Imported files cannot be found in the β€œtemp” folder.

This can be fixed by setting working directory the same as the one that contains the file by default when launching scss.

Compass compiler

Hi,

I start use the assetic bundle yesterday and i choosed to learn the compass filter. I followed the documentation and make my configuration (you can see it on the compass branch that i have pushed to the acme-assetic git project).

The problem is, when i go for production it doesn't compile. It is a configuration problem, what should i do?

Thanks

Warning: max()

app/console assetic:dump --watch --force

leads to

[error] Warning: max(): Array must contain at least one element in > /var/www/ads/vendor/assetic/src/Assetic/Asset/AssetCollection.php line 137

Fixed by checking count of array first around said line.

--no-debug and yui_js / yui_css working the wrong way

when i run assetic:dump --env=prod --no-debug, it outputs only the files as defined with output=...
whoever, those files are not compacted with the yui filters.

assetic:dump --env=prod without more options additinally dumps each individual file, but runs the yui filters for everything.

i think this is the wrong way round?
what i want is dumping only those files that a will need in production, and have them compressed...

by the way, accessing stylesheets through the controller delivers them not yui compressed, which is correct.

Cannot use all Compass functionalities

We don't directly use compass binary, so we cannot use compass options like images_dir in the CompassFilter. So, some functionalities like sprite cannot be used. A workaround will be to create a configuration file 'config.rb' with compass options in the same temp directory used for the temp sass/scss file. But it's an ugly way...
Or we can stop use sass --compass, and modify compass to be able to use add a load path (I've open a discussion on compass google groups)

filter for dynamic generated js/css files

Enhancement idea:
Sometimes, its necessary to create a dynamic js file to store some translations or ajax paths into js variables that are used somewhere in your scripts. On big web apps, those scripts can grow very fast and in order to have it compressed by assetic, one can then pass the localized variables to the object and still has all translations in one place.

Example for a global js var for translations/urls https://gist.github.com/1076036

Would be a very nice feature if assetic could parse dynamic php/twig files aswell and combine them to one.
Of course as the content changes when the user switches a language, the generated hash value should be a different one.

charset support

{% stylesheets 'css/foo.css' charset='utf-8' %}
<?php foreach (assetic_stylesheets('css/foo.css', null, array('charset' => 'utf-8')) as $url): ?>

Twig functions

Add a way for a filter to be a Twig function: pngout('images/logo.png')

asset namer interface

We need to move the asset naming logic from the asset factory to its own service. This should eliminate the circular reference from the asset factory to the asset manager.

Packager filter

Hi,

I think Packager can be a great addition as a filter. It uses yaml style comment in assets for dependency resolution. It's being used by mootools for its modular build. And although initially used for js, it also supports css.

see https://github.com/kamicane/packager for more info

Private/partial assets

You should be able to add an asset to the asset manager that can be used by other assets but never accessed directly.

Incorrect Content-Type on images

Assetic sets the Content-Type: text/html when serving PNG images (I haven't tried any other, and using optipng filter) when it should be image/png. The image renders fine when in HTML, but wierd characters are showed when clicking on "See Image" or similar.

PHP filter

a filter that parses the input as php

[Twig extension] Using a template variable in an asset's path?

I'm using Assetic in a Symfony2 project, from within twig templates. Problem is, I have an asset whose name is derived from a twig template variable. For example, I have a variable called myobject.slug that has a value of foobar-baz. I need to process web/css/foobar-baz.css with assetic.

I've tried using twig's concatenation operator (the tilde, ~), and it throws an Unexpected token "operator" of value "~" exception:

{% stylesheets filter='?yui_css'
    'css/' ~ myobject.slug ~ '.css'
%}
    <link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}

Is there a way to accomplish this, currently? If not, perhaps there ought to be?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.