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

Invisible Rewrites (mod_rewrite) - Asset Manager uses the pre-rewritten path to resolve #176

Open
mtudor opened this issue May 26, 2015 · 2 comments

Comments

@mtudor
Copy link

mtudor commented May 26, 2015

Hi guys, looking for a bit of input on this one please. We've just implemented a cache busting module which adds a rewrite rule to catch paths of the format (for example) /my/path/myfile.XX.XX.XX.js (where XX.XX.XX is a version number) and invisibly rewrite these to /my/path/myfile.js.

We are using the PathStackResolver, and AssetManager attempts to locate an asset with the pre-rewritten name including the version number. This doesn't find anything and the file access fails. My initial thought was whether AssetManager should actually be using the REDIRECT_URL parameter to grab the post-rewritten name excluding the version number? For example, this change:

https://github.com/RWOverdijk/AssetManager/blob/master/src/AssetManager/Service/AssetManager.php#L194

$fullPath   = $request->getServer('REDIRECT_URL') ?: $uri->getPath();

My concerns:

  • the reliability of REDIRECT_URL (possibly semi-negated by a $uri->getPath() fallback?).
  • whether there are circumstances you would actually want the pre-rewritten url, possibly in resolvers that are not path related.

I've been talking in terms of cache-busting and version numbers but of course this would apply to any invisible rewrite situation... Appreciate your thoughts!

@RWOverdijk
Copy link
Owner

Why won't you just name the file myfile.xx.xx.xx.js?

Anyway, that's a valid question. You could rewrite the path before it hits AssetManager, using the same logic as your rewrite rule.

@mtudor
Copy link
Author

mtudor commented May 28, 2015

Hi Wesley, thanks for the response. The version numbering is automatically applied through an extension to headScript and headLink, which pulls the current release version from a config file updated by our build script. Renaming wouldn't be practical as we're doing it for every js / css file in the repository.

So, rewriting the path before it hits AssetManager - would you be thinking we do that within a small ZF2 module; changing the value in $uri->getPath()? Or did you have something else in mind?

Do you think that AssetManager should examine the content of REDIRECT_URL in order to cater for an invisible rewrite? That would either be a case of assuming that the resolver will always want the rewritten url if it exists, and passing that in as I outlined in my last comment, passing both urls in, or passing the whole Request object to the resolver and allowing it to handle as appropriate. Any thoughts?

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

2 participants