Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to add attributes (async, defer) to javascript requirements?


Go to End


1833 Views

Avatar
FlamyTwista

Community Member, 4 Posts

9 July 2016 at 6:42am

Hi there!
I'm trying to add JS with requirements, cause requirements adds cache-busting.
But I also need defer attribute in script tag.

	public function init() {
        Requirements::javascript("themes/mysite/builds/main.js");
	}

I've read documentation and source code, and don't found solution how to achieve it.

Is it possible to use requirements, cache-busting and defer attribute simultaneously?