0

I have a small bit of (localised) Javascript bundled with a plugin. Currently it's in a non-minified .js file, called at via enqueue_scripts.

Given that this script will likely run on every page, should I minify it or output it so it's inline in the page?

1
  • interesting question, but it is not related to wordpress. – Mark Kaplun Dec 17 '13 at 13:58
1

If you minify it you'll be able to reap the advantage of caching the file.

If you inline it, the browser will have to download the script every time it accesses a page with your plugin on it.

I'd minify it.

3
  • there are no advantages to catching the file if users only view one page of the site and then leave it. If you inline it you save an http request. – Mark Kaplun Dec 17 '13 at 14:00
  • I had thought about this but not really considered it seriously. This answer has a fairly detailed breakdown of how large the file needs to get before inlining starts harming performance: stackoverflow.com/questions/5987031/… (approx 62.5 KB) That answer ends up essentially saying 'it depends', but my gut would go with the http request as I'd consider repeat visitors a higher priority. – Gaffen Dec 17 '13 at 14:12
  • 1
    The chances for a file from a small site not to be purged before a second visit to the site is close to 0. The real use case is when the reader is expected to read another page at the same browsing session. I think "it depends" is the only possible answer. Personally I usually avoid inlining but that is because of code esthetics and not because of performance. – Mark Kaplun Dec 17 '13 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.