Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to serve file hash #99

Closed
jmleroux opened this issue Aug 27, 2013 · 7 comments
Closed

[Question] How to serve file hash #99

jmleroux opened this issue Aug 27, 2013 · 7 comments

Comments

@jmleroux
Copy link
Contributor

Hello,

I'm using the FilesystemCache for my assets but i don't know how to get the resulting hash to use it in my view template.

My asset (a css file foo.css), is hashed and i can view it in public/assets/application/808cc956bac63457eb33ca3edd9a4949.

Isn't this the right way to use assets in view layout ?

$this->headLink()->prependStylesheet(basePath('/assets/application/foo.css'));

Output

<link type="text/css" rel="stylesheet" media="screen" href="/mysite/public/assets/application/foo.css">

but i want something like this :

<link type="text/css" rel="stylesheet" media="screen" href="/mysite/public/assets/application/808cc956bac63457eb33ca3edd9a4949">
@RWOverdijk
Copy link
Owner

To be honest, I have absolutely no idea. I have never used that cache type
before (it's not optimal to do so). I'd recommend using the FilePathCache
type.

What I do know, is that it basically uses the hashes itself to find a
cache match. So you just use the key in stead of the hash name.

@jmleroux
Copy link
Contributor Author

Of course i will use FilePathCache for production, but FilesystemCache is good for development, as it refresh assets automatically.

Maybe I should use aliases, but I didn't find any doc.

@RWOverdijk
Copy link
Owner

Just use the path you'd normally use, the hash key is used by the cache
itself.

@jmleroux
Copy link
Contributor Author

OK for using FilePathCache in production.
There is just a problem with FilePathCache and FilesystemCache : say i have an asset css.foo.cs

The cache in production should be :

        'caching' => array(
            'default' => array(
                'cache' => 'FilePathCache',
                'options' => array(
                    'dir' => 'public',
                ),
            ),
        ),

then my file will be under public/css/foo.css

But if I change for FilesystemCache, the hashed file will be under public/1y23s4f5d6789.
This doesn't suits me.

Eventuallly, I would change the config for development :

        'caching' => array(
            'default' => array(
                'cache' => 'Filesystem',
                'options' => array(
                    'dir' => 'data/cache',
                ),
            ),
        ),

So in conclusion, I think that the cache configuration should go under config/autoload/asset_manager.local.php

The default .gitignore strategy will ignore this config and it will become environment-dependent.

It may be worth to say a word about this in the doc ?

@RWOverdijk
Copy link
Owner

We could do that. That might not be the worst idea :)

@Ocramius
Copy link
Contributor

@jmleroux that's absolutely for config/autoload

@jmleroux
Copy link
Contributor Author

The way I use this module, I split the config :

config/autoload/asset_manager.local.php essentialy for the cache configuration

assets.module.config.php in my modules, essentially for the resolvers : it's easier to set the paths for the module's assets from the module config path.

@RWOverdijk RWOverdijk mentioned this issue May 28, 2014
Closed
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants