title: WebGL detach and delete shaders after linking
body: <p>In OpenGL it is recommended to detach and delete shaders after linking the program ( <a href="https://stackoverflow.com/questions/9113154/proper-way-to-delete-glsl-shader">Proper way to delete GLSL shader?</a> ). </p>
  
  <p>But when I do this in WebGL, it seems like both Safari and Firefox has problems (while Chrome behaves as expected). Does detach and delete shaders works different in WebGL or is it just the browser implementations that are not following the standard?</p>
  
  <p>The problem happens when I use this function:</p>
  
  <pre><code>function setupShader(){
      var vertexShaderSrc = document.getElementById('vertexShader').textContent;
      var fragmentShaderSrc = document.getElementById('fragmentShader').textContent;
      var vertexShader = gl.createShader(gl.VERTEX_SHADER);
      gl.shaderSource(vertexShader, vertexShaderSrc);
  gl.compileShader(vertexShader);
      if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
          alert(gl.getShaderInfoLog(vertexShader));
      }
      var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
      gl.shaderSource(fragmentShader, fragmentShaderSrc);
      gl.compileShader(fragmentShader);
      if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
          alert(gl.getShaderInfoLog(fragmentShader));
      }
      shaderProgram = gl.createProgram();
      gl.attachShader(shaderProgram, vertexShader);
      gl.attachShader(shaderProgram, fragmentShader);
      gl.linkProgram(shaderProgram);
  
      if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
          alert("Could not initialise shaders");
      }
      gl.useProgram(shaderProgram);
      gl.detachShader(shaderProgram, vertexShader);
      gl.detachShader(shaderProgram, fragmentShader);
      gl.deleteShader(vertexShader);
      gl.deleteShader(fragmentShader);    
  }
  </code></pre>
  
  <p>A full running example can be found here:
  <a href="http://jsfiddle.net/mortennobel/vdgtg3fy/1/" rel="nofollow noreferrer">http://jsfiddle.net/mortennobel/vdgtg3fy/1/</a></p>
  
  <p>Edit: A few more details: I'm running OS/X Yosemite. Safari 8.0, Chrome 39, Firefox 33.1. 
  It turns out that if I call gl.getUniformLocation(xxx) and store the result before I detach and delete the shader, then everything works fine. I know this is probably a good thing to do - but I'm still curious if this is something I must do - or it is a browser bug.</p>