parisholley / wordpress-asynchronous-javascript

Improve page load performance by asynchronously loading javascript and files using head.js in your wordpress website.
http://wordpress.org/extend/plugins/asynchronous-javascript/
24 stars 3 forks source link

Head.js being outputted in footer instead of head #5

Open DeanStr opened 11 years ago

DeanStr commented 11 years ago

As the name suggests, head.js should always be in the section, but if there are no scripts enqueued to be outputted in the header, and there are only scripts to be outputted in footer, then head.js is also outputted in the footer by this plugin instead of in the header.

parisholley commented 11 years ago

is this not the case already? filter_headjs() checks if scripts are queued before writing head.js

DeanStr commented 11 years ago

Yes, and so if there are no scripts queued in header, it won't write head.js, but then if there are scripts queued in footer, it will write head.js in the footer. It should be writing head.js in the header regardless of where the other scripts are queued.

If you still don't understand what I'm saying:

If there are no scripts queued at all (none in header and none in footer), head.js isn't written, this works correct. If there are scripts queued in both header and in footer, head.js is written in header, this works correct. If there are scripts queued in header but none in footer, head.js is written in header, this works correct. If there are scripts queued in footer but not in header, head.js is written in footer, this is the problem, head.js should be written in the header and then the head.js() call is only in the footer.

So, in the last example, with scripts queued in footer but none in header, it currently outputs:

<html>
<head>
</head>
<body>
...
<script type="text/javascript" src="head.load.min.js"></script>
<script type="text/javascript">head.js({script:script.js}, {script1:script1.s});</script>
</body>
</html>

When it should output:

<html>
<head>
<script type="text/javascript" src="head.load.min.js"></script>
</head>
<body>
...
<script type="text/javascript">head.js({script:script.js}, {script1:script1.s});</script>
</body>
</html>
parisholley commented 11 years ago

sorry, misread. perhaps it could be a configurable option, but it does not need to be in the header always unless you need to use other features of headjs (which isn't the intention of this plugin).

parisholley commented 11 years ago

another issue is how do you know to put headjs in the header if scripts aren't queued until after wordpress renders the header? you would need to have a "always include" feature for this to work

DeanStr commented 11 years ago

Well thats why I created an issue and not a pull request, because I wasn't sure how to do it. An always include feature would solve the issue. Would you like me to create a pull request for always include feature?

parisholley commented 11 years ago

sure, otherwise I will put it in next version that goes out