Resource interpreted as other but transferred with MIME type text/javascript.

When I was looking at a site with the Chrome Developer Tools, it had a little error icon that said “Resource interpreted as other but transferred with MIME type text/javascript” when I clicked it.

I couldn’t figure out my error at first, but eventually realized I had for some reason had a script tag with a src assigned of blank and then had javascript between the source tags.


<script type="text/javascript">doSomething();</script>

A blank url or src is of course a reference to the current page. I don’t know why it took me so long to figure that out, but once I changed the page I realized the error.

Hope this helps!

Dealing With Dates in JavaScript

JavaScript’s Date object is pretty good, but not exactly standardized across all of the different browsers. In a recent project, I had a need to add dates, determine if it was a leap year and determine number of hours between different times, which would have required a ton of utility code and logic.

Datejs also adds a lot of awesome methods and other functionality that allows developers to stop worrying so much about dates and just get the project working. Datejs allowed me to get the project done on time and focus on developing an awesome site!

How to Add CSS & JavaScript to a CMS Page

Magento is an insanely flexible system that has a lot of potential, but of course with this flexibility comes a lot of learning.

Adding a JavaScript file and a CSS file to a specific CMS page isn’t very difficult. We should always consider adding the JavaScript file or CSS file to the theme if we’re going to use it on more than one specific page.

We setup a reference and use the name=”head” and then we’re able to add whatever actions that we would like. It’s fairly simple and makes use of XML, so be careful with closing tags. :)

By default CSS files are looked for in /skin/frontend/base/default/css and javascript files are looked for in /skin/frontend/base/default/js but you are able to specify different paths and really should! For CSS files just change the type to css.

<reference name="head">
  <action method="addItem">
    <type>js</type><script>yourjsfile.js</script>
  </action>
</reference>


Hope this helps!

Coders at Work: Reflections on the Craft of Programming

Coders at Work written by Peter Seibel is a fantastic book of interviews of fifteen very famous programmers. Audience of the book is clearly programmers with experience programming as the book can at times get fairly rich with technical details about compilers, IDE’s, etc. The book contains some fairly lengthy interviews, but reads fairly quickly, that are usually very interesting although a few I did not finish reading because of profanity or lack of interest (women in technology related.)

Seibel asks each “coder” a series of similar questions, and then usually branched off into their particular interests or whatever they were famous for. Seibel’s questions are very open ended which allowed for some very good discussion. One of the best questions that Seibel asks is perhaps about how the programmer reads source code, some of the answers were really quite enlightening because they went against how I would have approached the problem.

Crockford, for example, spends a fairly large amount of time discussing JavaScript and some of the pitfalls with it. One of the underlying themes that most of the interviewees seem to bring up is that we should make things simpler, less coupled, and to stop reinventing the wheel.

The book suffers in a few ways from absolutely terrible binding, paper that feels extremely cheap (newspaper ?), and sometimes very broad questions that make the reader feel fairly uninterested. The book is mostly a look into historical programming, and doesn’t contain any newer technologies like .NET, RoR, etc so if you are only interested in the past don’t bother reading this book.

Component returned failure code: 0x805e000a


Error: uncaught exception: [Exception... "Component returned failure code: 0x805e000a [nsIXMLHttpRequest.open]"
nsresult: "0x805e000a ()"

AdBlock interferes with the XmlHTTPRequest object and is known to sometimes break the way jQuery functions especially if the url triggers some sort of url filter.

You have a few options to resolve the solution:

  • suggest that users turn off AdBlock if the class called global_message exists.
  • Change the url posting or geting from.

Inline vs External JavaScript

In general, we never should have embed JavaScript inside the same file as the HTML markup and should instead place the JavaScript into an external file.

The content, presentation, and interaction code should all be separate to make your life easier as a website developer.

  • Cleaner Code. Cleaner code is much quicker to find errors in, and will reduce the complexity. In addition, changes only need to be made in one file instead of in potentially dozen resulting in a significant saving of your time and money for your client.
  • JavaScript will be better cached for future use and will reduce the size of the HTML file. Users won’t need to download the file every time the user revisits resulting in very quick retrieval.
  • Different Parsing Systems. The parsing systems used for HTML/XHTML are vastly different from the parsing/compiler systems used for JavaScript are different and can introduce nested quote problems.

JavaScript And Site Performance

JavaScript and the respective frameworks have really began to gain traction over the last couple of years. I would argue that most of the JavaScript frameworks are excellent, and truly are great for the user experience and for the programmer experience.

Unfortunately, many of the JavaScript frameworks are quite large for a web page. jQuery, for example, minified is nearly 56KB. Personally, I wouldn’t use jQuery or another JavaScript framework for static pages that might only read an XML file or display a simple animation: frameworks really are elegant for web applications. The size of frameworks isn’t much of an issue for people on broadband (cable, dsl, etc), but now as web developers we are beginning to see iPODs, iPhones, Blackberries, and other smaller electronics beginning to view our websites where the size and download speed of the frameworks, and website markup can begin to create havoc.

First, we should move all of the JavaScript to the bottom of the body because each HTTP request for an external document will block the rendering of the HTML until downloading has completed. JavaScript according to the W3C can “appear any number of times in the HEAD or BODY of an HTML document.”

Web Developers should also minimize the number of HTTP requests by combining all of the JavaScript into one file, and all of the css into a single css file. The Yahoo developer blog contains some really helpful tips. Yahoo also provides an excellent plugin for Firefox/Firebug that provides some tips and debug-type of information.

Browser Redirection – Yahoo Answers

I am having problems getting mozilla firefox to display my website correctly. It works fine on Internet Explorer. So I was thinking of making a mirror of the website that is made specifically for firefox browsers. Is it possible to code a website so that it detects what browser a visitor is using and them sends them to the correct mirror ?(i.e. index_firefox.html or index_ie.html)

Background Information
At the root of this question, there lies a huge problem that really never would have occured if browser creators followed the w3c recommendations. Microsoft and Netscape fought the original browser wars in the 1990s and throughout this time both created proprietary nonstandard tags and didn’t always follow the w3c recommendations. Eventually, Microsoft’s Internet Explorer won the war and Netscape disappeared into the oblivion to eventually become the Mozilla Project.

Mozilla Firefox, Opera, Safari and Chrome basically render almost exactly (99% of the time) the current w3c recommendations for css,html, and javscript and most of the draft recommendations are followed in the current builds of these browsers. Internet Explorer on the other hand, barely follows any of the w3c recommendations from even the year 2000. IE’s terrible rendering results in us having to perform significant testing and spend significant amounts of time doing IE6, IE7, and probably now IE8 hacks.

Problems With Potential Solution
I believe that redirecting based on a browser is a terrible idea, and should be avoided at all costs because of the potential doubling or trippling of work with regards to content.

Also, what happens if the browser doesn’t have javascript support of a user has turned it off? Chrome, Firefox,Opera, and Safari users would continue to be dished out a crap website that only works on some version of IE.

My Solution
Avoid the use of redirections for different browsers and instead developing a website that is 100% standards compliant and than start to add IE hacks as necessary.

Mouse Overs For ASP.NET

Have you ever wanted to have the ability for the colour of a row to change when your user moves the mouse over top of a particular row, and then change the colour back whenever the cursor is moved back off?

Well, this process isn’t very difficult in fact using some knowledge of JavaScript & the Document Object Model (DOM) we can dynamically change the background colour.

We need to override the Render class and then add some attributes to each GridViewRow before the page is finally output to the browser.

In this example, I have called the gridview we are adding the mouseovers and mouseouts “gvClients” because it displays a list of my fictional company’s clients. Wherever you see gvClients you need to make sure that you change this to your respective gridview’s name.

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
   /*Using a simple foreach we iterate through the Rows and use the row.Attributes.Add() and pass in the javascript property we want to output as    html, along with the function we will use and then because asp.net usually dynmically creates the names for each item we need to use    the row.ClientID as this will exist only on the client side.
*/
foreach (GridViewRow row in gvClients.Rows)
{
  row.Attributes.Add(“onmouseout”, “ColorGridForMouseOut(‘” + row.ClientID + “‘);”);
  row.Attributes.Add(“onmouseover”, “ColorGridForMouseOver(‘” + row.ClientID + “‘);”);
}

//We finally just pass in the html that’s now been created.
base.Render(writer);
}

— Sample javascript

//Change Color of Gridview on MouseOut
function ColorGridForMouseOver(id) {
var el = document.getElementById(id);

if(el.currentStyle) // for msie
{
if (el.style.backgroundColor !=’orange’)
{
el.style.backgroundColor=’lightblue’;
el.style.cursor=’hand’;
}
}
else // for real browsers ;)
{
if (el.style.backgroundColor != ‘Orange’)
{
el.style.backgroundColor = ‘lightblue’;
el.style.cursor = ‘pointer’;
}
}
}

function ColorGridForMouseOut(id)
{
var el = document.getElementById(id);

if(el.currentStyle) // for msie
{
if (el.style.backgroundColor !=’orange’)
{
el.style.backgroundColor=’White’;
el.style.textDecoration=’none’;
}
}
else // for real browsers ;)
{
if (el.style.backgroundColor != ‘Orange’)
{
el.style.backgroundColor = ‘White’;
el.style.textDecoration=’none’;
}
}
}

Thank you for taking the time to visit.

Slider by webdesign