Steve Workman
Steve Workman

Reputation: 325

How can I find out what jQuery functions I use in my scripts?

I'm attempting to audit my code so that I can find out what jQuery functions I use and how many of them I use. The goal is to remove jQuery and alias its functions with native browser implementations to save on page weight.

Simply put I want to match any jQuery function: $("#whatever").methodname(...

I have tried a basic regular expression to find the times where I use a jQuery selector, which looks a bit like this:

grep -r \$\([\"\'].+[\"\']\)\. jscript/*.js

However, this isn't working very well, and I also want it to match against function names and count them up for me. Can you help?

Upvotes: 1

Views: 307

Answers (1)

Elias Dorneles
Elias Dorneles

Reputation: 23896

You won't be able to do that with simple regex lookups.

You need a tool that understands JavaScript, like grasp.

With grasp installed, you could do grasp '#$' file.js to find the references to the $ variable.

Upvotes: 2

Related Questions