Code Monkey home page Code Monkey logo

Comments (6)

zohararad avatar zohararad commented on September 25, 2024

Hmm it seems like the wrong place to initialize the code. Why are you not initializing the code at the end of the body?

from audio5js.

bjoerge avatar bjoerge commented on September 25, 2024

I don't see any good reason for this library to make assumptions about the DOM state. Moreover, this is not a problem in browsers supporting HTML5 audio. As Audio5js is a compatibility layer and the flash fallback should do its best to avoid introducing bugs in environments is providing compatibility for.

The fix is simple, just wrap the document.body.appendChild(d) in a domready event handler.

from audio5js.

bjoerge avatar bjoerge commented on September 25, 2024

Btw, the code above were just an illustrating example, I'm creating an instance of Audio5js in a script loaded via <script src="the-script.js" async defer></script>. This tag is located in <head> and that makes perfectly sense to me.

from audio5js.

zohararad avatar zohararad commented on September 25, 2024

Errr... the library does make the following (justifiable) assumptions:

  1. It's considered good practice to wait for end of or DOM readiness to run your JS code.
  2. You make some sacrifices if you need Flash-based audio because of the nature of Flash in the browser.

I don't think the library should concern itself with DOM readiness (which is in itself incompatible between browsers). If you implement the library, you should be mindful of the DOM manipulation in FF, which requires DOM readiness and implement the code accordingly.

I'm happy to add a note in README at reminds people of this, but I see no reason to change the code to check for DOM readiness.

from audio5js.

bjoerge avatar bjoerge commented on September 25, 2024

It's considered good practice to wait for end of or DOM readiness to run your JS code.

That is true for the parts of the JS code that interacts with the DOM. There are perfectly good reasons to run javascript that doesn't care about the DOM before the DOM ready (side point: I don't really feel it is in the Audio5js mandate to enforce good practice on its users, it is a compatibility layer after all).

You make some sacrifices if you need Flash-based audio because of the nature of Flash in the browser.

That is true for the unavoidable sacrifices (like flash installed). However, my point is that "wait for dom ready" is a hidden requirement that isn't really necessary and are causing surprising errors. Sure, a note in the README will help those who fine read it, but is in my opinion not a proper fix.

Anyways, I've fixed this by including the domready lib in my fork. I sense that a pull request is not too welcome here, so I'll just keep it to myself for now ;-)

from audio5js.

zohararad avatar zohararad commented on September 25, 2024

Hmm, i'm afraid we'll have to agree to disagree. My sentiment is that Audio5js should solve HMTL5 audio compatibility issues and that's all.

Yes, DOM readiness is a hidden requirement, but it's also a hidden requirement for the Facebook JS SDK which doesn't immediately strikes one as DOM-reliant. I don't see why you can't simply use your own DOM readiness mechanism inside the section of your code, since you're aware of that requirement.

In other words, why should Audio5js be responsible for DOM readiness detection, when:

  1. Audio5js is an HTML5 audio compat. layer, rather than a DOM readiness compat. layer
  2. The developer most likely already uses a DOM library and has the facility to detect DOM readiness in a cross platform way.
  3. For the most part Audio5js doesn't manipulate the DOM

from audio5js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.