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

Image paths in CSS files incorrect when bundled #5

Open
RudeySH opened this issue Jan 27, 2017 · 0 comments
Open

Image paths in CSS files incorrect when bundled #5

RudeySH opened this issue Jan 27, 2017 · 0 comments

Comments

@RudeySH
Copy link

RudeySH commented Jan 27, 2017

Relative paths in CSS files tend to cause problems with ASP.NET bundling, because ASP.NET can place the bundled CSS file in a different folder than where the original CSS files came from, without moving the images or patching the image paths.

Dynamic Bundles generates bundles that are placed on the root of the web site, while the images remain in the "Views/{Controller}/{Action}" folder, without patching the relative image paths.

It may seem Dynamic Bundles works at first, but that's because bundling & minimization only happens in Release mode, or when BundleTables.EnableOptimizations is explicitly set to true.

To fix it, these are some of the options available:

  1. Ensure the bundles are placed in the same folder as the original CSS file(s). This will not work if the bundle consists of multiple CSS files that are not all in the same folder.
  2. Use CssRewriteUrlTransform. See this thread on StackOverflow, it does not work when your application is running in an IIS virtual directory.
  3. Use a custom IBundleTransform implementation or an extended StyleBundle class that patches the relative image paths.

If the CSS bundles that Dynamic Bundles generate always consist of CSS files that come from the same folder, option 1 seems to be the easiest solution. If not, for the sake of completeness I'd say skip option 2 and go for the custom implementation. This seems like a good start.

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

1 participant