Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderscore template in HTML generating mysterious 404 errors
    text
    copied!<p>Okay, I have this underscore template (simplified version), rendered from <code>_template.html.erb</code>, in my Rails app, somewhere on the page:</p> <pre><code>&lt;script type="text/html" id="mytemplate"&gt; &lt;div class="foo"&gt; &lt;img src="{{= my_variable }}" /&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>Then I render it like this, elsewhere, when required:</p> <pre><code>// change it to mustache-style because of defaults clashing with erb _.templateSettings = { interpolate: /\{\{\=(.+?)\}\}/g, evaluate: /\{\{(.+?)\}\}/g }; options = { my_variable: '/foo/bar/baz.img' } compiled = _.template($("#mytemplate").html()); $(compiled(options)).appendTo("#wherever"); </code></pre> <p>This, in theory should work just fine and it does, except errors like this started popping up in server logs and elsewhere, browsers 404-ing on URLs like: <code>http://example.com/{{=%20my_variable%20}}</code>, or <code>http://example.com/foo/{{=%20my_variable%20}}</code>.</p> <p>Now, my <strong>hunch</strong> is that it has something to do with the fact that it's an <code>img</code> tag and somehow the browser tries to <code>GET</code> it from the page, even though it's wrapped in <code>script</code> tags, but I have no idea why on earth. This is one of the recommended methods by many people for embedding underscore templates into HTML. And I can't attribute it to older browsers and/or robots either because server logs show these are real people using the latest Chrome etc.</p> <p>Edit: after a bit more investigating, 1. it only happens to a few people (unique IPs) 2. all of them are using the latest version of Chrome. So maybe it's an extension gone haywire?</p> <p>Any ideas?</p>
 

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