Which of these two forms is the best way to access the .css and .js files?

0

Currently I have an application where I access different .js and .css files and I do it in the following way:

<link href='vista/assets/style/index.css' rel='stylesheet' type='text/css'>

That form is the most standard I know and what it does is communicate to the daughter folders from a base.

But I've also seen the following way:

$host="http://localhost:8080/softicket/SoftTicket/trunk/";

    <link href=<?php echo $host.'/vista/assets/style/index.css' ?> rel='stylesheet' type='text/css'>

The two forms work correctly, but the number two form gets the whole route and the first only accesses to daughter folders. I do not know if there is much difference or it gives exactly the same the way in which said web elements are accessed.

The truth is that my situation is that I want that when uploading to a server or having to change the server and let's say the route will be modified constantly in the future, it is only a possibility, then you will want to see the fastest way to make that change easy to do and to assimilate.

    
asked by David 22.07.2017 в 21:41
source

1 answer

1

Really the best way to do it with the first option, using PHP within the HTML code is not a very good idea at present, we want less spaghetti code.

Observation: The correct way to import your styles is:

<link type="text/css" rel="stylesheet" href="tu_ruta/tu_archivo.css"/>

The type attribute can be omitted from HTML5, but for previous versions of HTML you should use it.

The .js files should be imported with the following syntax:

<script src="tu_ruta/tu_archivo.js"></script>
    
answered by 22.07.2017 / 22:58
source