core-bundle/src/Resources/contao/library/Contao/Template.php
public static function generateScriptTag($src, $async=false, $mtime=false, $hash=null, $crossorigin=null)
	{
		// Add the filemtime if not given and not an external file
		if ($mtime === null && !preg_match('@^https?://@', $src))
		{
			$container = System::getContainer();
			$rootDir = $container->getParameter('kernel.project_dir');

			if (file_exists($rootDir . '/' . $src))
			{
				$mtime = filemtime($rootDir . '/' . $src);
			}
			else
			{
				$webDir = StringUtil::stripRootDir($container->getParameter('contao.web_dir'));

				// Handle public bundle resources in web/
				if (file_exists($rootDir . '/' . $webDir . '/' . $src))
				{
					$mtime = filemtime($rootDir . '/' . $webDir . '/' . $src);
				}
			}
		}

		if ($mtime)
		{
			$src .= '?v=' . substr(md5($mtime), 0, 8);
		}

		return '<script src="' . $src . '"' . ($async ? ' async' : '') . ($hash ? ' integrity="' . $hash . '"' : '') . ($crossorigin ? ' crossorigin="' . $crossorigin . '"' : '') . '></script>';
	}
public static function generateScriptTag($src, $async=false, $mtime=false, $hash=null, $crossorigin=null)
	{
		// Add the filemtime if not given and not an external file
		if ($mtime === null && !preg_match('@^https?://@', $src))
		{
			$container = System::getContainer();
			$rootDir = $container->getParameter('kernel.project_dir');

			if (file_exists($rootDir . '/' . $src))
			{
				$mtime = filemtime($rootDir . '/' . $src);
			}
			else
			{
				$webDir = StringUtil::stripRootDir($container->getParameter('contao.web_dir'));

				// Handle public bundle resources in web/
				if (file_exists($rootDir . '/' . $webDir . '/' . $src))
				{
					$mtime = filemtime($rootDir . '/' . $webDir . '/' . $src);
				}
			}
		}

		if ($mtime)
		{
			$src .= '?v=' . substr(md5($mtime), 0, 8);
		}

		return '<script src="' . $src . '"' . ($async ? ' async' : '') . ($hash ? ' integrity="' . $hash . '"' : '') . ($crossorigin ? ' crossorigin="' . $crossorigin . '"' : '') . '></script>';
	}
Generate the markup for a JavaScript tag

@param string      $src         The script path
@param boolean     $async       True to add the async attribute
@param mixed       $mtime       The file mtime
@param string|null $hash        An optional integrity hash
@param string|null $crossorigin An optional crossorigin attribute

@return string The markup string