Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Better yet (IMHO) implement a custom Bundle that fixes the image paths. I wrote one for my app. </p> <pre><code>using System; using System.Collections.Generic; using IO = System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.Optimization; </code></pre> <p>...</p> <pre><code>public class StyleImagePathBundle : Bundle { public StyleImagePathBundle(string virtualPath) : base(virtualPath, new IBundleTransform[1] { (IBundleTransform) new CssMinify() }) { } public StyleImagePathBundle(string virtualPath, string cdnPath) : base(virtualPath, cdnPath, new IBundleTransform[1] { (IBundleTransform) new CssMinify() }) { } public new Bundle Include(params string[] virtualPaths) { if (HttpContext.Current.IsDebuggingEnabled) { // Debugging. Bundling will not occur so act normal and no one gets hurt. base.Include(virtualPaths.ToArray()); return this; } // In production mode so CSS will be bundled. Correct image paths. var bundlePaths = new List&lt;string&gt;(); var svr = HttpContext.Current.Server; foreach (var path in virtualPaths) { var pattern = new Regex(@"url\s*\(\s*([""']?)([^:)]+)\1\s*\)", RegexOptions.IgnoreCase); var contents = IO.File.ReadAllText(svr.MapPath(path)); if(!pattern.IsMatch(contents)) { bundlePaths.Add(path); continue; } var bundlePath = (IO.Path.GetDirectoryName(path) ?? string.Empty).Replace(@"\", "/") + "/"; var bundleUrlPath = VirtualPathUtility.ToAbsolute(bundlePath); var bundleFilePath = String.Format("{0}{1}.bundle{2}", bundlePath, IO.Path.GetFileNameWithoutExtension(path), IO.Path.GetExtension(path)); contents = pattern.Replace(contents, "url($1" + bundleUrlPath + "$2$1)"); IO.File.WriteAllText(svr.MapPath(bundleFilePath), contents); bundlePaths.Add(bundleFilePath); } base.Include(bundlePaths.ToArray()); return this; } } </code></pre> <p>To use it, do:</p> <pre><code>bundles.Add(new StyleImagePathBundle("~/bundles/css").Include( "~/This/Is/Some/Folder/Path/layout.css")); </code></pre> <p>...instead of...</p> <pre><code>bundles.Add(new StyleBundle("~/bundles/css").Include( "~/This/Is/Some/Folder/Path/layout.css")); </code></pre> <p>What it does is (when not in debug mode) looks for <code>url(&lt;something&gt;)</code> and replaces it with <code>url(&lt;absolute\path\to\something&gt;)</code>. I wrote the thing about 10 seconds ago so it might need a little tweaking. I've taken into account fully-qualified URLs and base64 DataURIs by making sure there's no colons (:) in the URL path. In our environment, images normally reside in the same folder as their css files, but I've tested it with both parent folders (<code>url(../someFile.png)</code>) and child folders (<code>url(someFolder/someFile.png</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload