New to immediately-invoked function expression with JavaScript, curious about placement At the end of the immediately-invoked function expression, there is an if statement that checks the screen width and loads in some resources. I'm curious if it is best practice to include this logic inside my IIFE, or outside. Both seem to function the same as far as I can tell, though I'm curious if there is preferred/best way this should be done.

Also of interest to me, inside the IIFE I have a if/if else/else statement. I'm curious if the last else, with the return in it is necessary. Does it offer any benefits or should I remove it.

Feedback is much appreciated!

Below is the code I'm working with:

(function(w){
    w.loader = function(filetype, filename, mediaquery){

      var head = document.getElementsByTagName("head")[0],
          stylesheet = document.createElement('link'),
          script = document.createElement('script'),
          filetype = filetype.toLowerCase(); // normalize filetype data for use in conditions

      // If file type is set to CSS, create dynamic stylesheet link element
      if (filetype === 'css'){
        stylesheet.type = 'text/css';
        stylesheet.rel = 'stylesheet';
        stylesheet.href =  (filename + '.css');
        stylesheet.media = (mediaquery) ? mediaquery : 'screen'; // Use screen for media unless otherwise specified
        // If a file name has been specified, append dynamic stylesheet link element
        if (filename.length){
          head.appendChild(stylesheet);
        }
      }
      // If file type is set to JS, create dynamic script element link
      else if(filetype === 'js'){
        script.type = 'text/javascript';
        script.src = (filename + '.js');
        // If a file name has been specified, append dynamic script element
        if (filename.length){
          head.appendChild(script);
        }
      }
      else{
        return;
      }

    };

    if(Math.max(screen.width,window.outerWidth) &gt; 600 ){
      alert("Large Screen");
      loader('CSS', 'large-screen');
      loader('JS', 'large-screen');
    }

  }(this));

  /*
  if(Math.max(screen.width,window.outerWidth) &gt; 600 ){
    alert("Large Screen");
    loader('CSS', 'large-screen');
    loader('JS', 'large-screen');
  }
  */
In this case, it makes no difference at all.  This IIFE really has no reason for even being there because all it contains is a single function.  Your code does use any of the usual benefits of an IIFE (like a local and protected scope) or capturing the arguments in a closure.  

So the additional code that doesn't have any local variables of its own and doesn't use the passed in argument does not benefit at all from being in the IIFE, but there is no harm in putting it in the IIFE either.