npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

currentscript

v1.1.1

Published

Polyfill of HTML5's `document.currentScript`

Downloads

178

Readme

document.currentScript

GitHub Latest Release Build Status Sauce Test Status Dependency Status Dev Dependency Status

Sauce Test Status

A polyfill of HTML5's document.currentScript for IE 6-10 ONLY.

Public Service Announcement (PSA)

This polyfill will not work in IE11 because of a critical design choice made Microsoft ("Don't Call Me IE!") [1][2][3][4] in order to avoid consumers receiving an unnecessarily downgraded experience on websites that were making logic branch and feature decisions based on browser detection rather than feature detection.

However, Microsoft Edge (a.k.a. "Spartan", a.k.a. IE12) does natively support document.currentScript. This is likely due in part to you lovely consumers upvoting this issue on the IE Platform Suggestion Forum, so thank you!

Overview

Strict

This polyfill is configured do its best to comply with the HTML spec's definition of the correct behavior for document.currentScript.

More particularly, this will get the script element that was the source of the nearest currently executing code but ONLY if said source script is being evaluated synchronously for the first time by the browser.

In other words, if code is being operated on after its initial evaluation (e.g. async callbacks, functions invoked by user actions, etc.), then document.currentScript will always return null.

Loose

If you are interested in getting the currently executing script [regardless of the source/trigger of the exection], take a look at JamesMGreene/currentExecutingScript instead.

Browser Compatibility

| Browser | Version | Works? | Notes | |---------|---------:|:-----------:|---------------------------------------| | IE | 6 | Yes | Must use document._currentScript(). | | IE | 7 | Yes | Must use document._currentScript(). | | IE | 8 | Yes | | | IE | 9 | Yes | | | IE | 10 | Yes | | | IE | 11 | No! | IE removed script.readyState but didn't add document.currentScript yet! :astonished: See PSA for more info. | | Edge | * | Yes | Natively supports document.currentScript. | | * | * | Maybe...? | Only if the browser natively supports document.currentScript. |

Installation

NPM

npm install currentscript

GitHub

Alternatively, you can download/clone its GitHub repo: JamesMGreene/document.currentScript

Usage

IE 8-10

var scriptEl = document.currentScript;

IE 6-7

var scriptEl = document._currentScript();

Configuration

doNotDeferToNativeMethod

To support better cross-browser support, the default behavior of this polyfill in browsers other than IE 6-10 is to attempt to retrieve the native document.currentScript accessor method and use it as a last-ditch fallback effort.

However, if you would prefer to disallow that fallback behavior, you can do so as follows:

document._currentScript.doNotDeferToNativeMethod = true;

Other Documentation

  • MDN docs: https://developer.mozilla.org/en-US/docs/Web/API/document.currentScript

Errata

  • Demo using old Gist: http://jsfiddle.net/JamesMGreene/9DFc9/
  • Original location, old Gist: https://gist.github.com/JamesMGreene/fb4a71e060da6e26511d