Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import JavaScript files with CSS

Is it possible to use a CSS import file to import JavaScript pages?

@import url(Script.js);
like image 647
henryaaron Avatar asked Dec 03 '22 00:12

henryaaron


2 Answers

The spec states the URL has to point to a style sheet:

The '@import' rule allows users to import style rules from other style sheets. Any @import rules must follow all @charset rules and precede all other at-rules and rule sets in a style sheet. The '@import' keyword must be followed by the URI of the style sheet to include. A string is also allowed; it will be interpreted as if it had url(...) around it.

CSS3 Syntax Specification: http://www.w3.org/TR/css3-syntax/#import

like image 190
Šime Vidas Avatar answered Dec 20 '22 12:12

Šime Vidas


No, this syntax is not supported.

You can, however, use the src attribute of the <script> element to specify the location of an external script resource:

<script type="text/javascript" src="Script.js">
</script>
like image 38
Frédéric Hamidi Avatar answered Dec 20 '22 11:12

Frédéric Hamidi