I want to combine javascript-files into a single one to reduce the amount of requests to the server. Because there is no plugin for that, I want to code something by myself. Unfortunately the CMS has no central functions to include javascript-files which can be overwritten or something like that. So I'm forced to search and replace the script-tags in the source, before php will print the outout to the user.
To get the links I wrote a regex-pattern which matches on any script-tag with src-attribute:
$scriptTagPattern = '#<script (?:.+)?src="([^"]+)">#';
I think this should be correct because there are different script-tags. And I'm getting the source from template before they get parsed, so the src-attribute can also include php-code like this:
<script type="text/javascript" src="' . $options['baseurl'] . '/scripts/somejsfile.js"></script>
My pattern is working, but only partly. For example the following scripts are matched:
http://code.jquery.com/jquery-2.1.0.min.js
/scripts/yui/yuiloader-dom-event/yuiloader-dom-event.js
But the following is not matched:
<script type="text/javascript" src="scripts/read_marker.js?v=' . $options['simpleversion'] . '"></script>
I can't understand why my pattern does not match here. For example, the yuiloader (see examples above) has the following source which is similar to the read_marker script:
<script type="text/javascript" src="' . Template::fetchStylevar("yuipath") . '/yuiloader-dom-event/yuiloader-dom-event.js"></script>